Skip to content

perf(history): early-exit scanner for the history one-line preview (#1545) - #1599

Merged
ZhuchkaTriplesix merged 2 commits into
devfrom
issue/1545-history-preview-scanner
Oct 15, 2026
Merged

ZhuchkaTriplesix merged 2 commits into
devfrom
issue/1545-history-preview-scanner

Conversation

@ZhuchkaTriplesix

Copy link
Copy Markdown
Member

Summary

`_previewOneLine` ran `replaceAll(RegExp(r'\s+'), ' ').trim()` over the whole query before cutting it to 93 characters, so a 50-100 KB script in the history was copied in full for every row it showed.

`previewSqlOneLine` scans from the start, collapses whitespace on the fly (same character set as the regex `\s`), skips leading whitespace, and stops as soon as the preview is known to exceed 96 characters. Output is identical to the old code; the row widget still calls `_previewOneLine`, which now delegates.

Tests (not run locally; CI will)

`test/features/workspace/sql_query_history_preview_test.dart` compares the new function with the old collapse-then-cut implementation on empty / whitespace-only / exact-boundary (96, 97) / non-ASCII-whitespace / multi-line / very long inputs, and checks the cut length.

Closes #1545

_previewOneLine collapsed whitespace over the whole query with a regex and
only then cut it to 93 characters, so a 100 KB migration in the history was
copied whole for every row just to show its first line.

previewSqlOneLine reads characters from the start, collapses whitespace on
the fly and stops once the preview is known to be longer than 96. The output
is the same as before; a test compares it with the old implementation.

Closes #1545
@github-actions github-actions Bot added enhancement New feature or request performance Theme parser epic label: performance storage Theme parser epic label: storage core Core library logic and services P2 Medium priority / Parity & Refactoring labels Oct 15, 2026
@github-actions github-actions Bot added this to the 0.5.0 milestone Oct 15, 2026
@ZhuchkaTriplesix
ZhuchkaTriplesix merged commit b55cce9 into dev Oct 15, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Core library logic and services enhancement New feature or request P2 Medium priority / Parity & Refactoring performance Theme parser epic label: performance storage Theme parser epic label: storage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant