Skip to content

Commit 9dc42fa

Browse files
Merge pull request #1221 from QueryaHub/fix/1215-tab-dispose-shared-session
fix(table): closing a table tab releases its lease without interrupting the shared session (#1215)
2 parents b0dbac6 + e3a8db2 commit 9dc42fa

5 files changed

Lines changed: 25 additions & 41 deletions

File tree

‎lib/features/mysql/mysql_table_view.dart‎

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -233,21 +233,11 @@ class MysqlTableDataDelegate extends TableDataMutationDelegate {
233233
});
234234
}
235235

236+
/// Pooled sessions are shared with every other view of this database, so
237+
/// cancelling never closes them: a statement that is still running finishes
238+
/// or times out on its own, and the lease is released by [dispose].
236239
@override
237-
void cancel({bool interruptIfBusy = false}) {
238-
if (interruptIfBusy) {
239-
MysqlService.instance.interrupt(
240-
connectionRow,
241-
database: database,
242-
mode: MysqlSessionMode.readOnly,
243-
);
244-
MysqlService.instance.interrupt(
245-
connectionRow,
246-
database: database,
247-
mode: MysqlSessionMode.tableWrite,
248-
);
249-
}
250-
}
240+
void cancel({bool interruptIfBusy = false}) {}
251241

252242
@override
253243
void dispose() {

‎lib/features/postgresql/postgres_table_view.dart‎

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -234,21 +234,11 @@ class PostgresTableDataDelegate extends TableDataMutationDelegate {
234234
});
235235
}
236236

237+
/// Pooled sessions are shared with every other view of this database, so
238+
/// cancelling never closes them: a statement that is still running finishes
239+
/// or times out on its own, and the lease is released by [dispose].
237240
@override
238-
void cancel({bool interruptIfBusy = false}) {
239-
if (interruptIfBusy) {
240-
PostgresService.instance.interrupt(
241-
connectionRow,
242-
database: database,
243-
mode: PgSessionMode.readOnly,
244-
);
245-
PostgresService.instance.interrupt(
246-
connectionRow,
247-
database: database,
248-
mode: PgSessionMode.tableWrite,
249-
);
250-
}
251-
}
241+
void cancel({bool interruptIfBusy = false}) {}
252242

253243
@override
254244
void dispose() {

‎lib/features/sqlite/sqlite_table_view.dart‎

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -221,19 +221,11 @@ class SqliteTableDataDelegate extends TableDataMutationDelegate {
221221
});
222222
}
223223

224+
/// Pooled sessions are shared with every other view of this database, so
225+
/// cancelling never closes them: a statement that is still running finishes
226+
/// or times out on its own, and the lease is released by [dispose].
224227
@override
225-
void cancel({bool interruptIfBusy = false}) {
226-
if (interruptIfBusy) {
227-
SqliteService.instance.interrupt(
228-
connectionRow,
229-
mode: SqliteSessionMode.readOnly,
230-
);
231-
SqliteService.instance.interrupt(
232-
connectionRow,
233-
mode: SqliteSessionMode.tableWrite,
234-
);
235-
}
236-
}
228+
void cancel({bool interruptIfBusy = false}) {}
237229

238230
@override
239231
void dispose() {

‎lib/features/workspace/generic_table_view.dart‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,8 @@ class GenericTableViewState extends material.State<GenericTableView> {
286286
void dispose() {
287287
TableViewCommandBridge.instance.unregister(owner: this);
288288
_resetStaging();
289-
widget.delegate.cancel(interruptIfBusy: true);
289+
// Closing the tab releases its lease. It must not interrupt the shared
290+
// session: other views of the database may be using it.
290291
widget.delegate.dispose();
291292
super.dispose();
292293
}

‎test/features/workspace/generic_table_view_relations_test.dart‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,15 @@ void main() {
8686
await t.pump();
8787
expect(find.byType(ErdView), findsNothing);
8888
});
89+
90+
testWidgets('closing a table tab releases its delegate without cancelling it',
91+
(t) async {
92+
final delegate = FakeTableDataDelegate();
93+
await pumpGenericTableView(t, delegate);
94+
await t.pumpWidget(const material.SizedBox());
95+
await t.pump();
96+
// The session is shared with other views: closing must not interrupt it.
97+
expect(delegate.cancelCount, 0);
98+
expect(delegate.disposeCount, 1);
99+
});
89100
}

0 commit comments

Comments
 (0)