Opt-Script - Reduce food_eaten

Place for sharing your game modifications for Life is Feudal: Your Own
User avatar
Eslake
 
Posts: 73
Joined: 30 Dec 2014, 17:15

Opt-Script - Reduce food_eaten

Post by Eslake » 21 May 2015, 22:44

This one was already cleaned up since I was using it to teach someone some of the basic concepts.

The game stores every food every character ever eats. While this actually doesn't add up to much, even on a high population server, every little bit helps.
The first run of this reduced our food_eaten table from over 1700 entries, to 242.

The game only needs to know the most recent 4 foods eaten, but to be safe, we keep 5.

USAGE
Run the script to create the procedure
proc_Reduce_food_eaten

Then, during maintenance, and AFTER BACKUP,
CALL proc_Reduce_food_eaten;

BACK UP the database before making any changes, specially before running scripts that modify data.
DO NOT call this procedure while the server is active. It is a maintenance script.


CREATE PROCEDURE `proc_Reduce_food_eaten`()
BEGIN
DECLARE CharacterID INT;
SET CharacterID=0;

CREATE TABLE IF NOT EXISTS `new_foods` LIKE `food_eaten`;
TRUNCATE TABLE `new_foods`;
-- in case it was left over somehow from a previous attempt.

chars_Loop: Loop
    -- Each character gets the same process
    SELECT `ID` INTO CharacterID FROM `character` WHERE `ID`>CharacterID ORDER BY `ID` LIMIT 1;

    INSERT INTO `new_foods` (`CharID`, `Time`, `FoodTypeID`, `Complexity`) SELECT `CharID`, `Time`, `FoodTypeID`, `Complexity` FROM food_eaten WHERE CharID=CharacterID ORDER BY `ID` DESC LIMIT 5;
    IF (SELECT COUNT(*) FROM `Character` WHERE `ID`>CharacterID)> 0 THEN
      ITERATE chars_Loop;
    ELSE
      LEAVE chars_Loop;
    END IF;
END LOOP chars_Loop;

-- Replacing the old food_eaten table with the new one
DROP TABLE `food_eaten`;
RENAME TABLE `new_foods` TO `food_eaten`;
END


-- As a copy/paste code snippet
Code: Select all
CREATE PROCEDURE `proc_Reduce_food_eaten`()
BEGIN
DECLARE CharacterID INT;SET CharacterID=0;
CREATE TABLE IF NOT EXISTS `new_foods` LIKE `food_eaten`;
TRUNCATE TABLE `new_foods`;-- in case it was left over somehow from a previous attempt.

chars_Loop: Loop
   -- Each character gets the same process.
   SELECT `ID` INTO CharacterID FROM `character` WHERE `ID`>CharacterID ORDER BY `ID` LIMIT 1;
   INSERT INTO `new_foods` (`CharID`, `Time`, `FoodTypeID`, `Complexity`)
    SELECT `CharID`, `Time`, `FoodTypeID`, `Complexity` FROM food_eaten WHERE CharID=CharacterID ORDER BY `ID` DESC LIMIT 5;
   IF (SELECT COUNT(*) FROM `Character` WHERE `ID`>CharacterID)> 0 THEN
      ITERATE chars_Loop;
   ELSE
      LEAVE chars_Loop;
   END IF;
END LOOP chars_Loop;
-- Replacing the old food_eaten table with the new one.
DROP TABLE `food_eaten`;
RENAME TABLE `new_foods` TO `food_eaten`;
END
Last edited by Eslake on 22 May 2015, 16:10, edited 2 times in total.


Gms0012
 
Posts: 166
Joined: 23 Feb 2015, 08:49

Re: Opt-Script - Reduce food_eaten

Post by Gms0012 » 22 May 2015, 06:18

good input.. :)

thx
Image

User avatar
Razoreqx
 
Posts: 91
Joined: 06 Oct 2014, 13:13

Re: Opt-Script - Reduce food_eaten

Post by Razoreqx » 22 May 2015, 15:10

much thanks!! Works great
Razors Edge
A Life is Feudal Persistent World
http://razors-edge.org
22 Custom MODS / Custom Graphics models Planned. Visit our Gallery.

Return to Game mods