Skip to content

fix(schema): one cache, keyed by connection, and DDL that names its database (#288, #289, #290) - #640

Merged
EVWorth merged 2 commits into
mainfrom
fix/schema-connection-scoping
Sep 11, 2026
Merged

EVWorth merged 2 commits into
mainfrom
fix/schema-connection-scoping

Conversation

@EVWorth

@EVWorth EVWorth commented Sep 11, 2026

Copy link
Copy Markdown
Owner

Three schema findings with one shape: state that didn't say which server it was about.

#290 — DDL could read the wrong database

The DDL reads ran USE <database> and then an unqualified SHOW CREATE, as two statements against a pool. With pool_max > 1 the second isn't guaranteed to land on the session the first one changed, so it either failed with "no database selected" or returned the object of that name from whichever database that connection happened to be pointing at. Silently, and only sometimes. The USE error was discarded with let _ =, so the cause never surfaced either.

All four reads now name `db`.`object` and run one statement. Verified on MySQL 8.0.46 and MariaDB 11 for tables, views, procedures, functions and triggers.

The identifiers are quoted properly on the way in. A name reaching the inspector comes from the schema rather than a text box, so this is a second line rather than the first — but a table can be named anything, and a name read back from information_schema isn't thereby safe to splice into SQL. The SQL export had the same gap, where it produced statements that don't parse.

#288 — connections shared a cache

The tree kept its schema in component state keyed only by database name. mysql and app are on nearly every server, so two connections showed each other's objects and a context-menu action ran against whichever server the tree had been built from. A response arriving after a switch repopulated the new tree with the old server's tables.

#289 — refresh reached the wrong cache

A database-level refresh reloaded only tables, leaving views, routines and triggers as they were when the node first opened. The toolbar's full refresh cleared a different cache that the tree never read — so the tree stayed stale while the autocomplete updated, and a refresh from the tree did the opposite.

One store

Both are one store now, keyed by connection, with a generation counter per connection: a fetch captures it before awaiting and drops its result if it no longer matches. Invalidation is scoped — a folder, a database and all its folders, or the whole connection — and the autocomplete reads the same store rather than keeping a second copy of the same objects, so schemaCacheStore is deleted. Disconnecting forgets what was known, which also stops the cache growing by one server per session.

Two things the work turned up:

  • Generations have to live outside the store. Held in it, forgetting a connection reset them to zero — which is exactly what an in-flight fetch captured, so a response landing after a disconnect matched and was applied.
  • A selector returning a fresh empty object for an unknown connection compares unequal every render and re-renders the tree forever.

Verification

2541 unit + 341 browser tests. 23 new store tests, 4 new tree tests, 4 live-server Rust tests. The Rust tests fail against the old USE-then-SHOW code (2 of 4 reproduce it directly); the tree tests fail against both a shared cache and shared expansion state.

Closes #288
Closes #289
Closes #290

🤖 Generated with Claude Code

…atabase

Three schema findings with one shape: state that did not say which server it
was about.

#290 — the DDL reads ran `USE <database>` and then an unqualified
`SHOW CREATE`, as two statements against a pool. With `pool_max > 1` the
second is not guaranteed to land on the session the first one changed, so it
either failed with "no database selected" or returned the object of that name
from whichever database that connection happened to be pointing at. Silently,
and only sometimes. The `USE` error was discarded with `let _ =`, so the cause
never surfaced either.

All four now name `` `db`.`object` `` and run one statement. Verified on MySQL
8.0.46 and MariaDB 11 for tables, views, procedures, functions and triggers.

The identifiers are quoted properly on the way in. A name reaching the
inspector comes from the schema rather than a text box, so this is a second
line rather than the first — but a table can be named anything, and a name
read back from information_schema is not thereby safe to splice into SQL. The
SQL export had the same gap, where it produced statements that do not parse.

#288 — the tree kept its schema in component state keyed only by database
name. `mysql` and `app` are on nearly every server, so two connections showed
each other's objects and a context-menu action ran against whichever server
the tree had been built from. A response arriving after a switch repopulated
the new tree with the old server's tables.

#289 — refreshing had the matching problem. A database-level refresh reloaded
only tables, leaving views, routines and triggers as they were when the node
first opened. The toolbar's full refresh cleared a *different* cache that the
tree never read, so the tree stayed stale while the autocomplete updated, and
a refresh from the tree did the opposite.

Both are one store now, keyed by connection, with a generation counter per
connection: a fetch captures it before awaiting and drops its result if it no
longer matches. Invalidation is scoped — a folder, a database and all its
folders, or the whole connection — and the autocomplete reads the same store
rather than keeping a second copy of the same objects, so `schemaCacheStore`
is gone. Disconnecting forgets what was known, which also stops the cache
growing by one server per session.

Two things the work turned up: generations have to live outside the store, or
forgetting a connection resets them to zero — which is what an in-flight fetch
captured, so a response landing after a disconnect matched and was applied.
And a selector returning a fresh empty object for an unknown connection
re-renders the tree forever.

Co-Authored-By: Claude Opus 5 <[email protected]>
…tore

`scripts/check-test-mocks.sh` caught these in CI, which is what it is for:
Vitest ignores a `vi.mock` whose path resolves to nothing, so both files were
quietly running against the real module.

Co-Authored-By: Claude Opus 5 <[email protected]>
@EVWorth
EVWorth merged commit c4e7da3 into main Sep 11, 2026
12 checks passed
@EVWorth
EVWorth deleted the fix/schema-connection-scoping branch September 11, 2026 22:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant