• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

TFS 1.X+ Delete all players storage, except some

roriscrave

Advanced OT User
Joined
Dec 7, 2011
Messages
1,210
Solutions
35
Reaction score
206
How can i delete all players storage, except, storage: 10020, 10021, 10022, 1599100, 959911, 87727, 817277, 198882, 100929, 98828.
I need to delete all database player storages, except the ones I mentioned above
 
Solution
You need to write an SQL statement.
Something like this:
SQL:
Delete from table 
where storage_id not in (10020, 10021, 10022, 1599100, 959911, 87727, 817277, 198882, 100929, 98828)

you must change Table and storage_id by your right table and column.
You need to write an SQL statement.
Something like this:
SQL:
Delete from table 
where storage_id not in (10020, 10021, 10022, 1599100, 959911, 87727, 817277, 198882, 100929, 98828)

you must change Table and storage_id by your right table and column.
 
Solution
You need to write an SQL statement.
Something like this:
SQL:
Delete from table
where storage_id not in (10020, 10021, 10022, 1599100, 959911, 87727, 817277, 198882, 100929, 98828)

you must change Table and storage_id by your right table and column.

I thought that way (I think it might not be the best way), but does anyone have another smarter solution?
this function may cause a lag but will only be used once

LUA:
local storages_blocked = {10020, 10021, 10022, 1599100, 959911, 87727, 817277, 198882, 100929, 98828, 500, 9006} -- storage that dont remove
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    for i = 1, 999999 do
        if not table.contains(storages_blocked, i) then
            db.query("DELETE FROM `player_storage` WHERE `player_storage`.`key` = " .. i .. ";")
        end
    end
    return true
end
 
The operation you suggested is far more costly in terms of computation. The fastest way is the one I suggested.
If you are gonna run this just once, what's the problem? Or do you want to do this deletion every few minutes/hours? If so maybe you can reduce the impact only deleting the rows filtering by player and run it, maybe, everytime a player logs in. This way you spread the CPU usage over time and avoid freezing.
But there is not cost save at all doing a query and then deleting row by row inside a loop, comparing to a single SQL operation.
 
What you mean by a smarter solution? In my eyes, it would mean something thats simple and the fastest solution. Spekdrum has already provided the best answer.

Do you want the code just to look good? If so, that's a terrible approach.
 
Back
Top