-
-
Notifications
You must be signed in to change notification settings - Fork 297
fix(tabs): keep a restored table tab on its own database and load it after reconnect #1719
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,7 +32,12 @@ extension MainContentView { | |
| !selectedTab.tableContext.databaseName.isEmpty, | ||
| selectedTab.tableContext.databaseName != session.activeDatabase | ||
| { | ||
| Task { await coordinator.switchDatabase(to: selectedTab.tableContext.databaseName) } | ||
| Task { | ||
| await coordinator.switchDatabase( | ||
| to: selectedTab.tableContext.databaseName, clearTabs: false | ||
| ) | ||
| coordinator.lazyLoadCurrentTabIfNeeded() | ||
|
Comment on lines
+35
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When Useful? React with 👍 / 👎. |
||
| } | ||
| } else if let selectedTab = tabManager.selectedTab, | ||
| let tabSchema = selectedTab.tableContext.schemaName, | ||
| !tabSchema.isEmpty, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -963,13 +963,13 @@ final class MainContentCoordinator { | |
| ) | ||
| switch decision { | ||
| case .authorized: | ||
| executeQueryInternal(sql) | ||
| executeQueryInternal(sql, isAutoLoad: true) | ||
| case .denied(let reason): | ||
| tabManager.mutate(at: index) { $0.execution.errorMessage = reason } | ||
| } | ||
| } | ||
| } else { | ||
| executeQueryInternal(sql) | ||
| executeQueryInternal(sql, isAutoLoad: true) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This path is used by Useful? React with 👍 / 👎. |
||
| } | ||
| } | ||
|
|
||
|
|
@@ -1116,7 +1116,8 @@ final class MainContentCoordinator { | |
| } | ||
|
|
||
| internal func executeQueryInternal( | ||
| _ sql: String | ||
| _ sql: String, | ||
| isAutoLoad: Bool = false | ||
| ) { | ||
| guard let (selectedTab, index) = tabManager.selectedTabAndIndex, | ||
| !selectedTab.execution.isExecuting else { return } | ||
|
|
@@ -1169,6 +1170,21 @@ final class MainContentCoordinator { | |
| currentQueryTask = Task { [weak self] in | ||
| guard let self else { return } | ||
|
|
||
| if isAutoLoad { | ||
| do { | ||
| try await services.databaseManager.ensureConnected(conn) | ||
| } catch { | ||
| await MainActor.run { [weak self] in | ||
| guard let self else { return } | ||
| tabManager.mutate(tabId: tabId) { $0.execution.isExecuting = false } | ||
| currentQueryTask = nil | ||
| toolbarState.setExecuting(false) | ||
| needsLazyLoad = true | ||
| } | ||
| return | ||
| } | ||
| } | ||
|
|
||
| let schemaTask: Task<FetchedTableSchema, Error>? | ||
| if needsMetadataFetch, let tableName { | ||
| schemaTask = Task { try await QueryExecutor.fetchTableSchema(connectionId: connId, tableName: tableName) } | ||
|
|
@@ -1262,6 +1278,10 @@ final class MainContentCoordinator { | |
| toolbarState.setExecuting(false) | ||
| if error is CancellationError || Task.isCancelled { return } | ||
| guard capturedGeneration == queryGeneration else { return } | ||
| if isAutoLoad, services.databaseManager.driver(for: connectionId)?.status != .connected { | ||
| needsLazyLoad = true | ||
| return | ||
| } | ||
| handleQueryExecutionError(error, sql: sql, tabId: tabId, connection: conn) | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When switching to a table tab in another PostgreSQL database, this path now reconnects the database and immediately lazy-loads the tab, but
switchDatabaseclearssession.currentSchemafor plugins that require reconnects (DatabaseManager+Sessions.swiftlines 267-272; PostgreSQL sets that capability inPostgreSQLPlugin.swiftline 124). For restored/open tabs in a non-default schema, the selected tab'stableContext.schemaNameis never restored beforelazyLoadCurrentTabIfNeeded(), so schema-dependent metadata/FK/row-edit fetches run against the default schema even though the tab belongs to another schema. RestorenewTab.tableContext.schemaNameafter the database switch and before auto-loading.Useful? React with 👍 / 👎.