fix: clear stale filters and tables on database/schema switch#240
fix: clear stale filters and tables on database/schema switch#240
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9b1befd7ff
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| toolbarState.databaseName = database | ||
| closeSiblingNativeWindows() | ||
| tabManager.tabs = [] | ||
| tabManager.selectedTabId = nil |
There was a problem hiding this comment.
Defer tab/session reset until switch succeeds
switchDatabase now clears UI/session state (toolbarState.databaseName, open tabs, sibling windows, and filter state) before any of the throwing switch operations run. If USE, switchDatabase, switchSchema, or reconnectSession fails, the catch path only shows an error and does not restore prior state, so users can lose their open tabs/windows and see the toolbar pointing at a database that was never actually switched to; this is a regression in failure scenarios and the reset should be moved after success (the same failure pattern is present in switchSchema).
Useful? React with 👍 / 👎.
|
|
||
| func loadSchema() async { | ||
| guard let driver = DatabaseManager.shared.driver(for: connectionId) else { return } | ||
| await schemaProvider.invalidateCache() |
There was a problem hiding this comment.
Remove unconditional cache invalidation from loadSchema
Calling invalidateCache() at the start of every loadSchema() introduces a race when schema loads are triggered close together (for example, PostgreSQL switch calls loadSchema() and reconnectSession also emits .databaseDidConnect, whose handler calls coordinator.loadSchema()). If one load is in flight, a second call can clear cachedDriver via invalidateCache() and then return early because isLoading is true, leaving schema tables loaded but column fetches/autocomplete broken until another reload.
Useful? React with 👍 / 👎.
Summary
filterStateManagerwhen switching databases/schemas to prevent stale filters from being appliedloadSchema()so sidebar fetcher doesn't return stale cached tablesswitchDatabase/switchSchemawithTask.yield()so sidebar immediately shows loading state instead of stale tablesQueryTab.buildBaseTableQuery()to share query-building logic betweenaddTableTaband tab restoreCloses #237
Test plan