Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions lib/features/mysql/mysql_table_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -233,21 +233,11 @@ class MysqlTableDataDelegate extends TableDataMutationDelegate {
});
}

/// Pooled sessions are shared with every other view of this database, so
/// cancelling never closes them: a statement that is still running finishes
/// or times out on its own, and the lease is released by [dispose].
@override
void cancel({bool interruptIfBusy = false}) {
if (interruptIfBusy) {
MysqlService.instance.interrupt(
connectionRow,
database: database,
mode: MysqlSessionMode.readOnly,
);
MysqlService.instance.interrupt(
connectionRow,
database: database,
mode: MysqlSessionMode.tableWrite,
);
}
}
void cancel({bool interruptIfBusy = false}) {}

@override
void dispose() {
Expand Down
18 changes: 4 additions & 14 deletions lib/features/postgresql/postgres_table_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -234,21 +234,11 @@ class PostgresTableDataDelegate extends TableDataMutationDelegate {
});
}

/// Pooled sessions are shared with every other view of this database, so
/// cancelling never closes them: a statement that is still running finishes
/// or times out on its own, and the lease is released by [dispose].
@override
void cancel({bool interruptIfBusy = false}) {
if (interruptIfBusy) {
PostgresService.instance.interrupt(
connectionRow,
database: database,
mode: PgSessionMode.readOnly,
);
PostgresService.instance.interrupt(
connectionRow,
database: database,
mode: PgSessionMode.tableWrite,
);
}
}
void cancel({bool interruptIfBusy = false}) {}

@override
void dispose() {
Expand Down
16 changes: 4 additions & 12 deletions lib/features/sqlite/sqlite_table_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -221,19 +221,11 @@ class SqliteTableDataDelegate extends TableDataMutationDelegate {
});
}

/// Pooled sessions are shared with every other view of this database, so
/// cancelling never closes them: a statement that is still running finishes
/// or times out on its own, and the lease is released by [dispose].
@override
void cancel({bool interruptIfBusy = false}) {
if (interruptIfBusy) {
SqliteService.instance.interrupt(
connectionRow,
mode: SqliteSessionMode.readOnly,
);
SqliteService.instance.interrupt(
connectionRow,
mode: SqliteSessionMode.tableWrite,
);
}
}
void cancel({bool interruptIfBusy = false}) {}

@override
void dispose() {
Expand Down
3 changes: 2 additions & 1 deletion lib/features/workspace/generic_table_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,8 @@ class GenericTableViewState extends material.State<GenericTableView> {
void dispose() {
TableViewCommandBridge.instance.unregister(owner: this);
_resetStaging();
widget.delegate.cancel(interruptIfBusy: true);
// Closing the tab releases its lease. It must not interrupt the shared
// session: other views of the database may be using it.
widget.delegate.dispose();
super.dispose();
}
Expand Down
11 changes: 11 additions & 0 deletions test/features/workspace/generic_table_view_relations_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,15 @@ void main() {
await t.pump();
expect(find.byType(ErdView), findsNothing);
});

testWidgets('closing a table tab releases its delegate without cancelling it',
(t) async {
final delegate = FakeTableDataDelegate();
await pumpGenericTableView(t, delegate);
await t.pumpWidget(const material.SizedBox());
await t.pump();
// The session is shared with other views: closing must not interrupt it.
expect(delegate.cancelCount, 0);
expect(delegate.disposeCount, 1);
});
}
Loading