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
4 changes: 4 additions & 0 deletions lib/features/extensions/extension_table_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,16 @@ class _ExtensionTableViewState extends material.State<ExtensionTableView> {
_totalRows = null;
_filterController.clear();
_filterActive = false;
_stagingBuffer?.dispose();
_stagingBuffer = null;
unawaited(_loadPage(refreshCount: true));
}
}

@override
void dispose() {
_stagingBuffer?.dispose();
_stagingBuffer = null;
_filterController.dispose();
super.dispose();
}
Expand Down Expand Up @@ -208,6 +211,7 @@ class _ExtensionTableViewState extends material.State<ExtensionTableView> {
_columns = dataResult.columns;
_rows = dataResult.rows;
_loading = false;
_stagingBuffer?.dispose();
if (!widget.isView && (_capabilities?.supportsMutations == true)) {
_stagingBuffer =
DataGridStagingBuffer(columns: _columns, rows: _rows);
Expand Down
7 changes: 6 additions & 1 deletion lib/features/mysql/mysql_sql_workspace.dart
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ class _MysqlSqlWorkspaceState extends material.State<MysqlSqlWorkspace> {
);
}
_lease?.release();
_stagingBuffer?.dispose();
_stagingBuffer = null;
_sqlController.dispose();
super.dispose();
}
Expand Down Expand Up @@ -244,6 +246,7 @@ class _MysqlSqlWorkspaceState extends material.State<MysqlSqlWorkspace> {
_rows = outRows;
_affectedRows = affected;
_lastExecutedSql = userSql;
_stagingBuffer?.dispose();
_stagingBuffer = cols.isNotEmpty
? DataGridStagingBuffer(columns: cols, rows: outRows)
: null;
Expand Down Expand Up @@ -325,8 +328,10 @@ class _MysqlSqlWorkspaceState extends material.State<MysqlSqlWorkspace> {
}

if (!mounted) return;
final newRows = _stagingBuffer!.effectiveRows;
_stagingBuffer?.dispose();
setState(() {
_rows = _stagingBuffer!.effectiveRows;
_rows = newRows;
_stagingBuffer = DataGridStagingBuffer(columns: _columns, rows: _rows);
_savingChanges = false;
});
Expand Down
7 changes: 6 additions & 1 deletion lib/features/postgresql/postgres_sql_workspace.dart
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,8 @@ class _PostgresSqlWorkspaceState extends material.State<PostgresSqlWorkspace> {
);
}
_dropLease();
_stagingBuffer?.dispose();
_stagingBuffer = null;
_sqlController.dispose();
super.dispose();
}
Expand Down Expand Up @@ -388,6 +390,7 @@ class _PostgresSqlWorkspaceState extends material.State<PostgresSqlWorkspace> {
_rows = outRows;
_affectedRows = result.affectedRows;
_lastExecutedSql = userSql;
_stagingBuffer?.dispose();
_stagingBuffer = cols.isNotEmpty
? DataGridStagingBuffer(columns: cols, rows: outRows)
: null;
Expand Down Expand Up @@ -478,8 +481,10 @@ class _PostgresSqlWorkspaceState extends material.State<PostgresSqlWorkspace> {
await conn.execute(txSql, timeout: to);

if (!mounted) return;
final newRows = _stagingBuffer!.effectiveRows;
_stagingBuffer?.dispose();
setState(() {
_rows = _stagingBuffer!.effectiveRows;
_rows = newRows;
_stagingBuffer = DataGridStagingBuffer(columns: _columns, rows: _rows);
_savingChanges = false;
});
Expand Down
7 changes: 6 additions & 1 deletion lib/features/sqlite/sqlite_sql_workspace.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ class _SqliteSqlWorkspaceState extends material.State<SqliteSqlWorkspace> {
.removeListener(_appSettingsListener);
_topFraction.dispose();
_lease?.release();
_stagingBuffer?.dispose();
_stagingBuffer = null;
_sqlController.dispose();
super.dispose();
}
Expand Down Expand Up @@ -206,6 +208,7 @@ class _SqliteSqlWorkspaceState extends material.State<SqliteSqlWorkspace> {
_rows = outRows;
_affectedRows = null;
_lastExecutedSql = userSql;
_stagingBuffer?.dispose();
_stagingBuffer = cols.isNotEmpty
? DataGridStagingBuffer(columns: cols, rows: outRows)
: null;
Expand Down Expand Up @@ -285,8 +288,10 @@ class _SqliteSqlWorkspaceState extends material.State<SqliteSqlWorkspace> {
}

if (!mounted) return;
final newRows = _stagingBuffer!.effectiveRows;
_stagingBuffer?.dispose();
setState(() {
_rows = _stagingBuffer!.effectiveRows;
_rows = newRows;
_stagingBuffer = DataGridStagingBuffer(columns: _columns, rows: _rows);
_savingChanges = false;
});
Expand Down
8 changes: 8 additions & 0 deletions lib/features/workspace/data_grid_staging_buffer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -315,5 +315,13 @@ class DataGridStagingBuffer extends ChangeNotifier {
}
return result;
}

@override
void dispose() {
_modifiedCells.clear();
_insertedRows.clear();
_deletedRowIndices.clear();
super.dispose();
}
}

3 changes: 3 additions & 0 deletions lib/features/workspace/result_grid_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,9 @@ class _VirtualResultGridState extends material.State<VirtualResultGrid> {
_horizontalController.dispose();
_verticalController.dispose();
_focusNode.dispose();
_sortedRows = const [];
_columnWidths = const [];
_columnOffsets = const [0];
super.dispose();
}

Expand Down
8 changes: 8 additions & 0 deletions lib/features/workspace/results_tab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ class _ResultsTabState extends material.State<ResultsTab> {
return filteredRows;
}

@override
void dispose() {
_memoColumns = null;
_memoEffectiveRows = null;
_cachedFilteredRows = const [];
super.dispose();
}

@override
Widget build(BuildContext context) {
return QueryaFadeSlide(
Expand Down
17 changes: 17 additions & 0 deletions test/features/workspace/data_grid_staging_buffer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -154,5 +154,22 @@ void main() {
expect(plan.statements[2].type, MutationType.delete);
expect(plan.statements[2].sql, 'DELETE FROM "public"."users" WHERE "id" = 3');
});

test('dispose clears internal collections and prevents further listener notifications', () {
buffer.setCell(0, 1, 'Alice Modified');
buffer.addRow(['4', 'Diana', 'diana@test.com']);
buffer.toggleDeleteRow(2);

expect(buffer.isDirty, isTrue);
expect(buffer.changeCount, 3);

buffer.dispose();

expect(buffer.isDirty, isFalse);
expect(buffer.changeCount, 0);
expect(buffer.modifiedCellCount, 0);
expect(buffer.insertedRowCount, 0);
expect(buffer.deletedRowCount, 0);
});
});
}
Loading