mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-29 17:28:53 +00:00
fix(item insertion): Fix mysql timeout when inserting too many items
This commit is contained in:
+25
-8
@@ -69,6 +69,8 @@ AddEventHandler('es:playerLoaded', function(source, _player)
|
||||
},
|
||||
function(inventory)
|
||||
|
||||
local tasks2 = {}
|
||||
|
||||
for i=1, #inventory, 1 do
|
||||
table.insert(userData.inventory, {
|
||||
name = inventory[i].item,
|
||||
@@ -104,19 +106,34 @@ AddEventHandler('es:playerLoaded', function(source, _player)
|
||||
canRemove = ESX.Items[k].canRemove,
|
||||
})
|
||||
|
||||
MySQL.Async.execute(
|
||||
'INSERT INTO user_inventory (identifier, item, count) VALUES (@identifier, @item, @count)',
|
||||
{
|
||||
['@identifier'] = player.getIdentifier(),
|
||||
['@item'] = k,
|
||||
['@count'] = 0
|
||||
}
|
||||
)
|
||||
local scope = function(item, identifier)
|
||||
|
||||
table.insert(tasks2, function(cb2)
|
||||
|
||||
MySQL.Async.execute(
|
||||
'INSERT INTO user_inventory (identifier, item, count) VALUES (@identifier, @item, @count)',
|
||||
{
|
||||
['@identifier'] = identifier,
|
||||
['@item'] = item,
|
||||
['@count'] = 0
|
||||
},
|
||||
function(rowsChanged)
|
||||
cb2()
|
||||
end
|
||||
)
|
||||
|
||||
end)
|
||||
|
||||
end
|
||||
|
||||
scope(k, player.getIdentifier())
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Async.parallelLimit(tasks2, 5, function(results) end)
|
||||
|
||||
table.sort(userData.inventory, function(a,b)
|
||||
return a.label < b.label
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user