fix: optimise segment deletion and cloning with bulk operations#6401
Merged
gagantrivedi merged 4 commits intomainfrom Dec 12, 2025
Merged
fix: optimise segment deletion and cloning with bulk operations#6401gagantrivedi merged 4 commits intomainfrom
gagantrivedi merged 4 commits intomainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 3 Skipped Deployments
|
Contributor
Docker builds report
|
Implement bulk UPDATE/DELETE operations for segment deletion to reduce database queries from O(n) to O(1), where n is the number of rules and conditions. This addresses high DB CPU from N+1 queries during segment deletion. Changes: - Move AuthorData to core/dataclasses.py for reuse - Add segments/services.py with optimized delete_segment function - Add async task for audit log creation to isolate from delete - Update views.py to use new service for API deletions
ad35100 to
3182311
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6401 +/- ##
========================================
Coverage 98.06% 98.06%
========================================
Files 1289 1292 +3
Lines 46293 46498 +205
========================================
+ Hits 45395 45599 +204
- Misses 898 899 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
- Remove unnecessary `from __future__ import annotations` - Move local import to top level in tasks.py - Simplify loop break logic (remove redundant break) - Add explicit query count (26) to test assertion
Move copy_rules_and_conditions logic to services.py with bulk operations: - Use bulk_create instead of individual saves for rules and conditions - Process rules level-by-level to maintain parent relationships - Reduces query count from O(n) to O(depth)
matthewelwell
previously approved these changes
Dec 12, 2025
Contributor
matthewelwell
left a comment
There was a problem hiding this comment.
Approved with a minor remaining comment.
khvn26
approved these changes
Dec 12, 2025
There was a problem hiding this comment.
This PR is being reviewed by Cursor Bugbot
Details
Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.
To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.
4 tasks
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.
Thanks for submitting a PR! Please check the boxes below:
docs/if required so people know about the feature!Changes
Optimize segment deletion and cloning to reduce database queries from O(n) to O(depth), where n is the number of rules and conditions. This addresses high DB CPU from N+1 queries.
Segment Deletion
segments/services.pywith optimizeddelete_segmentfunctionAuthorDatatocore/dataclasses.pyfor reuseSegment Cloning
copy_segment_rules_and_conditionsto services.pybulk_createinstead of individual saves for rules and conditionsQuery Count Improvements
How did you test this code?
Added unit tests with explicit query count assertions to verify O(depth) complexity.