Skip to content

perf(db): optimize SQL history pruning to use batching instead of per-insert COUNT(*) - #528

Merged
ZhuchkaTriplesix merged 1 commit into
devfrom
issue/525-batch-sql-history-pruning
Jul 29, 2026
Merged

perf(db): optimize SQL history pruning to use batching instead of per-insert COUNT(*)#528
ZhuchkaTriplesix merged 1 commit into
devfrom
issue/525-batch-sql-history-pruning

Conversation

@ZhuchkaTriplesix

Copy link
Copy Markdown
Member

Closes #525

Summary of Changes

  • Introduced _historyInsertCounts in LocalDb to track insertions per history bucket.
  • Updated recordSqlQueryHistory to trigger _pruneSqlQueryHistoryBucket lazily in batches of 10 insertions (reducing SQLite COUNT(*) and DELETE overhead by 90% during query execution).
  • Retained instant pruning for small caps (maxEntries <= 10) and explicit forcePrune: true for full backward compatibility with existing tests.
  • Added unit tests for batched history pruning in test/core/storage/sql_query_history_test.dart.

Verification

  • flutter test test/core/storage/sql_query_history_test.dart passed (8/8 tests).

@ZhuchkaTriplesix
ZhuchkaTriplesix merged commit 5366e75 into dev Jul 29, 2026
4 checks passed
@ZhuchkaTriplesix ZhuchkaTriplesix self-assigned this Jul 29, 2026
@ZhuchkaTriplesix
ZhuchkaTriplesix deleted the issue/525-batch-sql-history-pruning branch July 30, 2026 07:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant