Skip to content

Commit

Permalink
addition to inventory check at resource start
Browse files Browse the repository at this point in the history
- Showcase Video: https://youtu.be/5yYuwbX_A2c
after the inventory started, it checks every inventory. If the inventory got nothing inside ( empty ) it deletes the database line.
- So it keeps it organized and optimised
  • Loading branch information
LeSiiN authored May 27, 2024
1 parent ed5388d commit d7eb826
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,25 @@ CreateThread(function()
for i = 1, #result do
local inventory = result[i]
local cacheKey = inventory.identifier
Inventories[cacheKey] = {
items = json.decode(inventory.items) or {},
isOpen = false
}
local items = json.decode(inventory.items) or {}
if #items == 0 then
MySQL.Async.execute('DELETE FROM inventories WHERE id = @id', {
['@id'] = inventory.id
}, function(rowsChanged)
if rowsChanged > 0 then
print('Empty inventory with id ( ' .. inventory.id .. ' ) and name ( ' ..cacheKey.. ' ) removed')
else
print('Failed to remove empty inventory with id ( ' .. inventory.id .. ' ) and name ( ' ..cacheKey.. ' )')
end
end)
else
Inventories[cacheKey] = {
items = items,
isOpen = false
}
end
end
print(#result .. ' inventories successfully loaded')
print(#result .. ' inventories successfully checked and loaded')
end
end)
end)
Expand Down

0 comments on commit d7eb826

Please sign in to comment.