Optimize global digest lookups - #89
Open
moacirmoda wants to merge 1 commit into
Open
Conversation
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
createdAt desc, id desclatest-event semantics with regression coverage for same-instant tiesWhy
The global catch-up query ranked every message, channel, and member revision before applying its guild and time filters. As revision history grows, that makes a small incremental digest pay the cost of sorting unrelated history.
The correlated lookups constrain each latest-row search to its parent entity. The new timestamp index lets selective global catch-ups begin with the messages in range.
Query-plan evidence
Against the exact compiled global digest query on a disposable store with 100,000 synthetic messages, SQLite selected:
messages_discord_created_at_index (discord_created_at>?)message_revisions_message_id_created_at_index (message_id=?)channel_detail_revisions_channel_id_created_at_index (channel_id=?)member_detail_revisions_member_id_created_at_index (member_id=?)Removing the new index changed the outer access path from one global time-range lookup to repeated channel/time lookups through the pre-existing compound index.
Verification
pnpm run lintpnpm run tscpnpm run test:unittwice: 589/589 passed each timepnpm run test:e2e: 58/58 specs passed; 20/20 tools reached through real MCP trafficpnpm run test:seed-coverage: 17/20 tools demonstrated; the existing 3 live-Discord tools remained explicitly unseedablemessages_catch_upafter the final commit