From 08de3681c483e928c36552a7b616a855acff8498 Mon Sep 17 00:00:00 2001 From: PowerfulBacon <26465327+PowerfulBacon@users.noreply.github.com> Date: Fri, 9 Aug 2024 17:01:33 +0100 Subject: [PATCH] Fixes DB queries having unnecessary delayed starts (#10837) * Update dbcore.dm * a * Adds a get metabalance async proc --- code/controllers/subsystem/dbcore.dm | 15 ++++++++++----- code/modules/admin/admin.dm | 6 +++--- code/modules/metacoin/metacoin.dm | 3 +++ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/code/controllers/subsystem/dbcore.dm b/code/controllers/subsystem/dbcore.dm index fef1c161b433b..556af64d4f899 100644 --- a/code/controllers/subsystem/dbcore.dm +++ b/code/controllers/subsystem/dbcore.dm @@ -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 @@ -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)) @@ -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) diff --git a/code/modules/admin/admin.dm b/code/modules/admin/admin.dm index 9ff4dcaff230a..69b5da486bd91 100644 --- a/code/modules/admin/admin.dm +++ b/code/modules/admin/admin.dm @@ -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)]", "
Options for [M.key]
", 700, 600) + var/body = "Options panel for [M]" if(M.client) body += " played by [M.client]" @@ -69,8 +71,7 @@ body += "- " body += "= " body += "0" - var/metabalance = M.client.get_metabalance_db() - body += "
[CONFIG_GET(string/metacurrency_name)]s: [metabalance] " + body += "
[CONFIG_GET(string/metacurrency_name)]s: [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"]" @@ -219,7 +220,6 @@ body += "
" - var/datum/browser/popup = new(usr, "adminplayeropts-[REF(M)]", "
Options for [M.key]
", 700, 600) popup.set_content(body) popup.open(0) diff --git a/code/modules/metacoin/metacoin.dm b/code/modules/metacoin/metacoin.dm index febd06f1fe33a..2da399183dc72 100644 --- a/code/modules/metacoin/metacoin.dm +++ b/code/modules/metacoin/metacoin.dm @@ -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(