mirror of
https://github.com/Aurorastation/Aurora.3.git
synced 2025-12-25 09:31:13 +00:00
Better SQL prepared statements (#2474)
The system used to be of complexity O(n^2). Essentially two for loops running per every argument. Which ended up being surprisingly slow (there were instances where I saw the argument parser as using quite a lot of CPU time).
This replaces it with a more linear algorithm. It's somewhere near O(n) where n is the length of the unparsed query. Which is more stable and faaaster. This comes with two changes, however:
Parameters inside the query now have to be delimited from both sides with : (colons). The alternative to this would be to use something like $n or just assume that space marks the end of a marker. Only the former is workable, the latter would break a few queries already.
Arguments in the argument array no longer have to be prefixed by : (colons). So, while in the query you would write :thing:, you'd initialize the array of args as: list("thing" = somevar). It could be made to work without it, but eh, I think this is fine.
Argument validation is slightly weaker. What I mean by this is that with the old system, unused keys would result in an error. This is no longer a thing. Missing keys will still result in an error, however.
One more improvement: double delimiting removes an edge case where if key A partially covers key B, depending on the order, key A would mangle key B.
Updated and tested all queries that I could find. So this should be good.
This commit is contained in:
@@ -26,7 +26,7 @@
|
||||
"args" = list("id")))
|
||||
|
||||
/datum/category_item/player_setup_item/general/basic/gather_load_parameters()
|
||||
return list(":id" = pref.current_character)
|
||||
return list("id" = pref.current_character)
|
||||
|
||||
/datum/category_item/player_setup_item/general/basic/gather_save_query()
|
||||
return list("ss13_characters" = list("name",
|
||||
@@ -38,13 +38,13 @@
|
||||
"ckey" = 1))
|
||||
|
||||
/datum/category_item/player_setup_item/general/basic/gather_save_parameters()
|
||||
return list(":name" = pref.real_name,
|
||||
":gender" = pref.gender,
|
||||
":age" = pref.age,
|
||||
":metadata" = pref.metadata,
|
||||
":spawnpoint" = pref.spawnpoint,
|
||||
":id" = pref.current_character,
|
||||
":ckey" = pref.client.ckey)
|
||||
return list("name" = pref.real_name,
|
||||
"gender" = pref.gender,
|
||||
"age" = pref.age,
|
||||
"metadata" = pref.metadata,
|
||||
"spawnpoint" = pref.spawnpoint,
|
||||
"id" = pref.current_character,
|
||||
"ckey" = pref.client.ckey)
|
||||
|
||||
/datum/category_item/player_setup_item/general/basic/load_special()
|
||||
pref.can_edit_name = 1
|
||||
@@ -55,8 +55,8 @@
|
||||
|
||||
// Called /after/ loading and /before/ sanitization.
|
||||
// So we have pref.current_character. It's just in text format.
|
||||
var/DBQuery/query = dbcon.NewQuery("SELECT DATEDIFF(NOW(), created_at) AS DiffDate FROM ss13_characters WHERE id = :id")
|
||||
query.Execute(list(":id" = text2num(pref.current_character)))
|
||||
var/DBQuery/query = dbcon.NewQuery("SELECT DATEDIFF(NOW(), created_at) AS DiffDate FROM ss13_characters WHERE id = :id:")
|
||||
query.Execute(list("id" = text2num(pref.current_character)))
|
||||
|
||||
if (query.NextRow())
|
||||
if (text2num(query.item[1]) > 5)
|
||||
|
||||
Reference in New Issue
Block a user