diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d2b00539..65debbe13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,13 @@ Legend: ? = Other stuff ``` +(29/10/26): Version 2.2.10-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 + (29/10/26): Version 2.2.9-srcdslab ----------------------- ``` diff --git a/game/addons/sourcemod/scripting/sbpp_main.sp b/game/addons/sourcemod/scripting/sbpp_main.sp index d0a8dcd12..b18ca58ef 100644 --- a/game/addons/sourcemod/scripting/sbpp_main.sp +++ b/game/addons/sourcemod/scripting/sbpp_main.sp @@ -1177,18 +1177,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