MAINT: Ordering AttackResults by timestamp for perf - #2295
Merged
rlundeen2 merged 2 commits intoJul 31, 2026
Conversation
jsong468
reviewed
Jul 30, 2026
jsong468
reviewed
Jul 30, 2026
jsong468
reviewed
Jul 30, 2026
Make the indexable AttackResultEntry.timestamp column the single source of truth for History recency, replacing the non-indexable JSON-extract sort expression. Adds serving indexes + an Alembic migration that backfills timestamp from the legacy attack_metadata.updated_at/created_at keys. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 5ae8d0da-5198-4ac0-acd9-65e6f7b5d283
rlundeen2
force-pushed
the
rlundeen2-optimize-attack-history-query
branch
from
July 31, 2026 19:41
01790cf to
058d1a3
Compare
jsong468
approved these changes
Jul 31, 2026
…tack-history-query
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 & why
Loading Attack History in the GUI got slow at scale because the paginated query ordered and keyset-seeked on a JSON recency expression (
COALESCE(json_extract(attack_metadata,'$.updated_at'), ...)) that no index can serve; this makes the real, indexableAttackResultEntry.timestampcolumn the single source of truth for "last updated" recency so the ordering/seek is index-served.Changes
ORDER BY/ keyset seek / cursor now use thetimestampcolumn (timestamp DESC, id DESC). Removed the JSON recency expression and its SQLite/Azure overrides and the Python recency key.AttackResultsKeysetCursorsimplified to(timestamp, attack_result_id).attack_service.py): GUI edits (add message, branch, promote main) now bump thetimestampcolumn instead of writingmetadata.updated_at.metadata.created_atstays as a display-only field.d7e9f1a3b5c6): addsix_AttackResultEntries_conversation_id(dedup window) andix_AttackResultEntries_timestamp_id(ORDER BY + seek). Backfillstimestampfrom the legacyupdated_at/created_atJSON keys so manually-edited conversations keep their History order, and strips the redundantupdated_atkey. Downgrade restores it.