perf(sqlite): add secondary indexes for frontend queries#77
Merged
Androz2091 merged 1 commit intomainfrom May 2, 2026
Merged
Conversation
The exported SQLite database had only PRIMARY KEYs on its tables, so common frontend reads ended up doing full scans. Worst offenders: - activity: PK starts (event_name, day, ...), but most reads also filter on associated_guild_id or associated_channel_id, which the PK couldn't help with. - sessions: no PK at all; every read filters on started_date. - voice_sessions: PK leads with channel_id, but reads only filter on started_date. - dm_channels_data / guild_channels_data: PK on channel_id, but reads also group/filter by dm_user_id / guild_id. Add 6 secondary indexes built after bulk insert (so each row only writes once) and before VACUUM (so vacuum repacks the index pages too). Closes #14.
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.
Summary
Closes #14.
The client-side SQLite database (the one shipped to the browser via `/blob`) had only PRIMARY KEYs on its tables. Common frontend reads — top guilds, top channels, top DMs, sending times, usage stats, etc. — were doing full table scans on the `activity` table (which can have 100k+ rows on heavy users) plus the `sessions` and `voice_sessions` tables (which had no usable index for their date-range filters at all).
What's added
Six secondary indexes, built after bulk insert so each row only writes once, and before `VACUUM` so vacuum repacks the index pages too:
The picks were validated against every `SELECT` in `dumpus-app/src/hooks/data/use-*.ts` and `stores/database.ts`. Patterns the existing PKs already covered (e.g. global `event_name + day` time-range scans hit the activity PK directly) didn't get a redundant index.
Tradeoffs
Test plan