fix: Session search does an extra 2000-row listing pass on every query and still silently drops valid matches#777
Closed
sam-saffron-jarvis wants to merge 1 commit into
Conversation
…y and still silently drops valid matches
Owner
|
Integrated the session search optimization/fix into the main working copy; closing this PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
SearchOptionsinstead of a bare query/limit.internal/session.SQLiteStore.Search(...)so SQLite filters before limiting.SearchResultwith the session metadata the web handler needs, then removed the extraList(... Limit: 2000, SortByActivity: true)pass fromhandleSessionsSearch.Why this is high-value
The old
/v1/sessions/searchpath did two DB queries per request:List(... Limit: 2000, SortByActivity: true)to build an allowlist mapSearch(query, limit*4)to get raw FTS hits, then dedupe/filter in GoThat was expensive on an interactive per-keystroke path, and it still produced incorrect results:
limit*4window before deduping, hiding other sessionsThis change removes the extra listing pass entirely and lets SQLite return already-filtered, already-deduped session matches. That cuts handler work, avoids building a 2000-entry map on every search, reduces DB work from two queries to one in the hot path, and fixes the dropped-results bug.
Validation
gofmt -w internal/session/types.go internal/session/store.go internal/session/noop.go internal/session/sqlite.go internal/session/sqlite_test.go cmd/serve_handlers.go cmd/sessions.go cmd/serve_runtime_test.go internal/tui/sessions/browse.go internal/tui/sessions/browse_test.go cmd/serve_test.gogo build ./...go test ./...git diff --checkNew coverage added:
TestHandleSessionsSearch_DoesNotDropOlderMatchesOutsideRecent2000ListWindowTestSQLiteStoreSearchReturnsDistinctFilteredSessionMatches