Skip to content

fix(db): remove blocking SQL calls from connect/upgrade/fastquery paths - #9

Merged
Rushaway merged 5 commits into
masterfrom
fix/async-db-connections
Aug 27, 2026
Merged

fix(db): remove blocking SQL calls from connect/upgrade/fastquery paths#9
Rushaway merged 5 commits into
masterfrom
fix/async-db-connections

Conversation

@Rushaway

Copy link
Copy Markdown
Member

Summary

  • DB_TryConnect() fell back to a synchronous SQLite_UseDatabase()/SQL_ConnectCustom() connect whenever no "shop" entry existed in databases.cfg, blocking the game thread on every (re)connect in that configuration. Database.Connect() already falls back to an implicit local SQLite database for an unrecognized config name, so a single async call now covers both the MySQL and SQLite cases.
  • DB_FastQuery() used SQL_LockDatabase()/SQL_FastQuery(); now routed through Database.Query().
  • The legacy v1→v2 schema upgrade (DB_UgradeState_1) issued a nested, fully synchronous SQL_Query() per item category while iterating the old items table. The per-category fetches are now dispatched asynchronously together and joined with a pending counter before the migration continues (DROP TABLE/DB_CreateTables()).
  • Bumped plugin version to 3.0E10.

Test plan

  • Compile with the SourceMod 1.11+ compiler.
  • Fresh install with no "shop" databases.cfg entry: confirm it falls back to local SQLite without a main-thread stall.
  • sm_shop_clear_db still works end to end (exercises DB_FastQuery path... actually via DB_TQuery, unaffected — sanity check regardless).
  • Upgrade path: run against an old v1-schema shop.sqlite/DB with several item categories and confirm %sitems/%sboughts get populated correctly and DB_CreateTables() still runs exactly once at the end.

🤖 Generated with Claude Code

Copilot AI lite review requested due to automatic review settings August 27, 2026 05:00

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

DB_TryConnect() used a synchronous SQLite_UseDatabase()/SQL_ConnectCustom()
fallback when no "shop" entry existed in databases.cfg, blocking the game
thread on every (re)connect attempt in that configuration. Database.Connect()
already falls back to an implicit local SQLite database for an unknown
config name, so a single async call now covers both cases.

DB_FastQuery() used SQL_LockDatabase()/SQL_FastQuery(), and the legacy
v1->v2 schema upgrade (DB_UgradeState_1) issued a nested, fully
synchronous SQL_Query() per item category while iterating the old
`items` table. Both now go through Database.Query(); the per-category
upgrade fetches are dispatched together and joined with a pending
counter before the migration continues.

Bumped plugin version to 3.0E10.
SourcePawn requires globals to be declared before use in the same file;
it was declared after DB_UgradeState_1(), which referenced it first,
causing "undefined symbol" at compile time.
@Rushaway
Rushaway force-pushed the fix/async-db-connections branch from bc1824b to 6b302ed Compare August 27, 2026 07:00
Rushaway and others added 3 commits August 27, 2026 10:18
Removed the DB_EscapeString function that escapes strings for database queries.
DB_EscapeString was removed in e8d909c since PR #8 moved all query
building to Database.Format. The EscapeString() wrapper in shop.sp
was its only caller and has no callers of its own, so drop it too.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@Rushaway
Rushaway merged commit afafea3 into master Aug 27, 2026
2 checks passed
@Rushaway
Rushaway deleted the fix/async-db-connections branch August 27, 2026 11:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants