Optimization
About the optimization
Last updated
About the optimization
Last updated
function SaveCustomers()
if next(PlayersMotels) then
local selectList = ''
local formatQuery = ([[
SELECT '%s' AS owner, %s AS py, '%s' AS mtl, %s AS rmid, '%s' AS unq, '%s' AS reqs, %s as susp, '%s' as sh, %s as st, %s as ed, '%s' as wn
]])
local total = 0
for k,v in pairs(PlayersMotels) do
total+= 1
if selectList == '' then
selectList = ([[
UPDATE mx_motels u JOIN (%s
]]):format(formatQuery:format(k, v.pay, v.motel, v.roomId, v.uniq, json.encode(v.requests), v.suspended, json.encode(v.shared), v.startTime, v.endTime, json.encode(v.warn)))
goto continue
end
selectList = selectList .. ([[
UNION %s
]]):format(formatQuery:format(k, v.pay, v.motel, v.roomId, v.uniq, json.encode(v.requests), v.suspended, json.encode(v.shared), v.startTime, v.endTime, json.encode(v.warn)))
::continue::
end
if selectList == '' then return end
selectList = selectList .. [[
) AS t ON u.owner = t.owner
SET pay = py,
motel = mtl,
`roomId` = rmid,
uniq = unq,
requests = reqs,
suspended = susp,
`shared` = sh,
`startTime` = st,
`endTime` = ed,
`warn` = wn
]]
ExecuteSQL(selectList)
Debug('Saved ^2'..total..'^1 Customers(s) ^0')
end
end