Repository navigation
fix(notes): delete an object's note history in one batch - #17050
Merged
Merged
Conversation
delete_related_notes deleted each note's edit history from the per-note pre_delete receiver, about four queries per note, so deleting a finding with a hundred notes cost some 500 queries. It now reads the history ids once, deletes the notes with that receiver standing down, and deletes the history rows in one query. A note deleted on its own still takes its history through the receiver. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
blakeaowens
approved these changes
Nov 21, 2026
devGregA
approved these changes
Nov 21, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Nov 21, 2026
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.
Description
Deleting a finding (or an engagement, test, risk acceptance or benchmark) deletes its notes through
delete_related_notes. Each note's edit history was deleted by the per-notepre_deletereceiver indojo/notes/signals.py, about four queries per note, so the cost grew with the number of notes: a single-finding DELETE with 50 notes ran 312 queries, with 5 notes 131.delete_related_notesnow reads the notes' history ids in one query, deletes the notes with that receiver standing down (aContextVar, so it is thread and async safe), and deletes the history rows in one query. The rows deleted are the same; only the number of statements changes. A note deleted on its own (the note delete view, or any otherNotes.delete()) still takes its history through the receiver. The debug log line no longer runs aCOUNT(*)on every call.Test results
unittests/test_notes_delete_in_bulk.py: the query count ofdelete_related_notesis the same for 1 note and for 10 (17 vs 53 before the change), every note and history row is gone, another object's notes and history are kept, an object with no notes costs one query, and a note deleted on its own still takes its history. The two query-count tests fail ondevwithout the change.DELETE /api/v2/findings/<id>/(medians of 7 runs): 50 notes 312 to 115 queries, 0.108 s to 0.054 s of SQL; 5 notes 131 to 115 queries.test_api_notes_nplusone,test_apiv2_delete_preview,test_bulk_delete_findings_m2m,test_copy_model,test_risk_acceptance,test_risk_acceptance_api,test_note_ui_private_authz,test_apiv2_note_visibility,test_jira_helper,test_legacy_table_fk_removal,test_deduplication_logic): the same results with and without the change.ruff check(ruff 0.16.10,ruff.toml) passes ondojo/notes/.Documentation
No user-visible change; no documentation needed.
Checklist
dev.devbranch.🤖 Generated with Claude Code