fix(item insertion): Fix mysql timeout when inserting too many items

This commit is contained in:
Jérémie N'gadi
2017-10-07 10:30:24 +02:00
parent 7545b26690
commit 43946dcec4
+25 -8
View File
@@ -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)