Skip to content

Commit 46c5a52

Browse files
perf(mysql): yield during table browse row→string conversion
Re-land #422 onto dev — prior PR merged into issue/421 base and never reached the default branch. Closes #422
1 parent e2e1aac commit 46c5a52

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

‎lib/features/mysql/mysql_table_view.dart‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import 'package:flutter/material.dart' as material;
44
import 'package:mysql_client/mysql_client.dart';
55
import 'package:querya_desktop/core/database/mysql_connection.dart';
66
import 'package:querya_desktop/core/database/mysql_service.dart';
7+
import 'package:querya_desktop/core/database/result_row_string_convert.dart';
78
import 'package:querya_desktop/core/storage/local_db.dart';
89
import 'package:querya_desktop/features/mysql/mysql_sql_editor_dialog.dart';
910
import 'package:querya_desktop/features/mysql/mysql_table_utils.dart';
@@ -144,15 +145,20 @@ class _MysqlTableViewState extends material.State<MysqlTableView> {
144145
return rs.cols.map((c) => c.name.isNotEmpty ? c.name : 'col').toList();
145146
}
146147

147-
List<List<String>> _resultRows(IResultSet rs) {
148+
Future<List<List<String>>> _resultRowsAsync(IResultSet rs) async {
148149
final out = <List<String>>[];
150+
var n = 0;
149151
for (final row in rs.rows) {
150152
out.add(
151153
List.generate(
152154
row.numOfColumns,
153-
(i) => row.colAt(i) ?? 'NULL',
155+
(i) => resultCellToDisplayString(row.colAt(i)),
154156
),
155157
);
158+
n++;
159+
if (n % kResultStringConvertYieldEvery == 0) {
160+
await Future<void>.delayed(Duration.zero);
161+
}
156162
}
157163
return out;
158164
}
@@ -186,7 +192,7 @@ class _MysqlTableViewState extends material.State<MysqlTableView> {
186192
if (!mounted) return;
187193

188194
final colNames = _resultColumns(result);
189-
final stringRows = _resultRows(result);
195+
final stringRows = await _resultRowsAsync(result);
190196

191197
setState(() {
192198
_columnNames = colNames;
@@ -223,9 +229,10 @@ class _MysqlTableViewState extends material.State<MysqlTableView> {
223229
try {
224230
final result = await conn.execute(sql);
225231
if (!mounted) return;
232+
final stringRows = await _resultRowsAsync(result);
226233
setState(() {
227234
_columnNames = _resultColumns(result);
228-
_rows = _resultRows(result);
235+
_rows = stringRows;
229236
_rowsOnPage = _rows.length;
230237
_totalRowCount = null;
231238
_loading = false;

0 commit comments

Comments
 (0)