From 822d8c92ab1a4c25f5b11290722b543371b17226 Mon Sep 17 00:00:00 2001 From: Rushaway Date: Wed, 28 Oct 2026 01:10:36 +0100 Subject: [PATCH] perf: set the database charset once per connection in sbpp_main Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 8 +++++++ game/addons/sourcemod/scripting/sbpp_main.sp | 25 +++++++++++++------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fbd43d7e5..33bc5993f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,14 @@ Legend: ? = Other stuff ``` +(28/10/26): Version 2.2.6-srcdslab +----------------------- +``` +01. + sbpp_main no longer re-sets the database charset (a blocking + round trip on the main thread) on every admin cache rebuild; + it is set once per connection +``` + (26/10/26): Version 2.2.5-srcdslab (**Run updater required**) ----------------------- ``` diff --git a/game/addons/sourcemod/scripting/sbpp_main.sp b/game/addons/sourcemod/scripting/sbpp_main.sp index 7e4544e32..8745d20b4 100644 --- a/game/addons/sourcemod/scripting/sbpp_main.sp +++ b/game/addons/sourcemod/scripting/sbpp_main.sp @@ -1155,18 +1155,25 @@ public void GotDatabase(Database db, const char[] error, any data) return; } - DB = db; - char query[1024]; - // Set character set to UTF8MB4 in the database - // Use SetCharset to ensure charset is set synchronously before any operations - if (!DB.SetCharset("utf8mb4")) + // OnRebuildAdminCache() calls this again with the current handle for every cache part. + // Only a new connection needs its charset set: SetCharset() is a blocking round trip on + // the main thread that also waits for any threaded query in flight, and the charset it + // sets stays on the handle (also across the driver's automatic reconnects). + if (db != DB) { - LogToFile(logFile, "Failed to set database charset to utf8mb4, trying async method"); - // Fallback to async method - Format(query, sizeof(query), "SET NAMES utf8mb4"); - DB.Query(ErrorCheckCallback, query); + DB = db; + + // Set character set to UTF8MB4 in the database + // Use SetCharset to ensure charset is set synchronously before any operations + if (!DB.SetCharset("utf8mb4")) + { + LogToFile(logFile, "Failed to set database charset to utf8mb4, trying async method"); + // Fallback to async method + Format(query, sizeof(query), "SET NAMES utf8mb4"); + DB.Query(ErrorCheckCallback, query); + } } // The database can be ready before the first ReadConfig() (OnMapStart), and every