Skip to content

Commit

Permalink
Fixes DB queries having unnecessary delayed starts (#10837)
Browse files Browse the repository at this point in the history
* Update dbcore.dm

* a

* Adds a get metabalance async proc
  • Loading branch information
PowerfulBacon authored Aug 9, 2024
1 parent 9dce230 commit 08de368
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
15 changes: 10 additions & 5 deletions code/controllers/subsystem/dbcore.dm
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,15 @@ SUBSYSTEM_DEF(dbcore)
return
query.job_id = rustg_sql_query_async(connection, query.sql, json_encode(query.arguments))

/datum/controller/subsystem/dbcore/proc/queue_query(datum/db_query/query)
/datum/controller/subsystem/dbcore/proc/run_or_queue_query(datum/db_query/query)
if(IsAdminAdvancedProcCall())
return
// If we can immediately run the query, then do it
// We need no standby queries, since we should not be jumping the queue if there
// are others waiting.
if (length(queries_active) < max_concurrent_queries && length(queries_standby) == 0)
create_active_query(query)
return
queries_standby_num++
queries_standby |= query

Expand Down Expand Up @@ -492,7 +498,7 @@ Delayed insert mode was removed in mysql 7 and only works with MyISAM type table
if(!MC_RUNNING(SSdbcore.init_stage))
SSdbcore.run_query_sync(src)
else
SSdbcore.queue_query(src)
SSdbcore.run_or_queue_query(src)
sync()
else
var/job_result_str = rustg_sql_query_blocking(connection, sql, json_encode(arguments))
Expand All @@ -512,12 +518,11 @@ Delayed insert mode was removed in mysql 7 and only works with MyISAM type table

/// Sleeps until execution of the query has finished.
/datum/db_query/proc/sync()
while(status < DB_QUERY_FINISHED)
stoplag()
UNTIL(process())

/datum/db_query/process(delta_time)
if(status >= DB_QUERY_FINISHED)
return
return TRUE

status = DB_QUERY_STARTED
var/job_result = rustg_sql_check_query(job_id)
Expand Down
6 changes: 3 additions & 3 deletions code/modules/admin/admin.dm
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
to_chat(usr, "You seem to be selecting a mob that doesn't exist anymore.")
return

var/datum/browser/popup = new(usr, "adminplayeropts-[REF(M)]", "<div align='center'>Options for [M.key]</div>", 700, 600)

var/body = "<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'><body>Options panel for <b>[M]</b>"
if(M.client)
body += " played by <b>[M.client]</b>"
Expand Down Expand Up @@ -69,8 +71,7 @@
body += "<a href='?_src_=holder;[HrefToken()];modantagtokens=subtract;mob=[REF(M)]'>-</a> "
body += "<a href='?_src_=holder;[HrefToken()];modantagtokens=set;mob=[REF(M)]'>=</a> "
body += "<a href='?_src_=holder;[HrefToken()];modantagtokens=zero;mob=[REF(M)]'>0</a>"
var/metabalance = M.client.get_metabalance_db()
body += "<br><b>[CONFIG_GET(string/metacurrency_name)]s</b>: [metabalance] "
body += "<br><b>[CONFIG_GET(string/metacurrency_name)]s</b>: [M.client.get_metabalance_async()] "
var/full_version = "Unknown"
if(M.client.byond_version)
full_version = "[M.client.byond_version].[M.client.byond_build ? M.client.byond_build : "xxx"]"
Expand Down Expand Up @@ -219,7 +220,6 @@

body += "<br></body>"

var/datum/browser/popup = new(usr, "adminplayeropts-[REF(M)]", "<div align='center'>Options for [M.key]</div>", 700, 600)
popup.set_content(body)
popup.open(0)

Expand Down
3 changes: 3 additions & 0 deletions code/modules/metacoin/metacoin.dm
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
CRASH("Metacoin amount fetched before value initialized")
return metabalance_cached

/client/proc/get_metabalance_async()
return metabalance_cached || get_metabalance_db()

/// Gets the user's metabalance from the DB. Blocking.
/client/proc/get_metabalance_db()
var/datum/db_query/query_get_metacoins = SSdbcore.NewQuery(
Expand Down

0 comments on commit 08de368

Please sign in to comment.