Problem
In lib/core/storage/local_db.dart, the recordSqlQueryHistory method calls _pruneSqlQueryHistoryBucket on every single executed query. This pruning executes a SELECT COUNT(*) to check if the bucket exceeds maxEntries. Doing an O(N) count query on every history insert adds unnecessary overhead to query execution time as the history table grows.
Solution
Instead of strict pruning on every insert, implement batched lazy-pruning. For example, allow the bucket to grow up to maxEntries + 100, and only run the DELETE cleanup when the threshold is hit, deleting 100 rows in one go. Alternatively, maintain an in-memory counter per session.
Problem
In
lib/core/storage/local_db.dart, therecordSqlQueryHistorymethod calls_pruneSqlQueryHistoryBucketon every single executed query. This pruning executes aSELECT COUNT(*)to check if the bucket exceedsmaxEntries. Doing an O(N) count query on every history insert adds unnecessary overhead to query execution time as the history table grows.Solution
Instead of strict pruning on every insert, implement batched lazy-pruning. For example, allow the bucket to grow up to
maxEntries + 100, and only run theDELETEcleanup when the threshold is hit, deleting 100 rows in one go. Alternatively, maintain an in-memory counter per session.