-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimized database requests when removing resources #8192
Conversation
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughThe updates primarily enhance the deletion process of related resources in the CVAT project, task, job, and segment models. New methods for cascading deletions and optimized annotation removals were added, ensuring efficient resource management. Additionally, changes in the database migration file modify foreign key relationships for better integrity and consistency. Changes
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (4)
- cvat/apps/dataset_manager/task.py (1 hunks)
- cvat/apps/engine/migrations/0082_alter_labeledimageattributeval_image_and_more.py (1 hunks)
- cvat/apps/engine/models.py (8 hunks)
- cvat/apps/engine/views.py (1 hunks)
Additional comments not posted (18)
cvat/apps/engine/migrations/0082_alter_labeledimageattributeval_image_and_more.py (6)
14-23
: Field alteration forlabeledimageattributeval.image
is correct.The
image
field now usesDO_NOTHING
on delete, which is appropriate for preventing cascading deletions.
24-33
: Field alteration forlabeledshape.parent
is correct.The
parent
field now usesDO_NOTHING
on delete and allows null values, which is appropriate for maintaining the hierarchical structure without cascading deletions.
34-43
: Field alteration forlabeledshapeattributeval.shape
is correct.The
shape
field now usesDO_NOTHING
on delete, which is appropriate for preventing cascading deletions.
44-53
: Field alteration forlabeledtrack.parent
is correct.The
parent
field now usesDO_NOTHING
on delete and allows null values, which is appropriate for maintaining the hierarchical structure without cascading deletions.
54-63
: Field alteration forlabeledtrackattributeval.track
is correct.The
track
field now usesDO_NOTHING
on delete, which is appropriate for preventing cascading deletions.
64-73
: Field alteration fortrackedshapeattributeval.shape
is correct.The
shape
field now usesDO_NOTHING
on delete, which is appropriate for preventing cascading deletions.cvat/apps/dataset_manager/task.py (1)
445-445
: Optimized deletion process in_delete
method is correct.The
_delete
method now uses thedelete_related_resources
method ofdb_job
, which consolidates the deletion process for related resources.cvat/apps/engine/models.py (10)
347-347
: Modification inProject.get_labels
method is correct.The method now returns all label sets, which is appropriate for the project's requirements.
366-373
:Project.delete_related_resources
method optimizes deletion process.The method efficiently deletes labels and attributes, preventing redundant deletions.
376-378
: Modification inProject.delete
method is correct.The method now calls
delete_related_resources
before deletion, ensuring efficient resource management.
444-444
: Modification inTask.get_labels
method is correct.The method now returns all label sets, which is appropriate for the task's requirements.
483-493
:Task.delete_related_annotations
method optimizes deletion process.The method efficiently deletes related annotations, preventing redundant deletions.
494-503
:Task.delete_related_resources
method optimizes deletion process.The method efficiently deletes labels and attributes, preventing redundant deletions.
506-508
: Modification inTask.delete
method is correct.The method now calls
delete_related_resources
before deletion, ensuring efficient resource management.
786-795
:Job.delete_related_annotations
method optimizes deletion process.The method efficiently deletes related annotations, preventing redundant deletions.
796-798
:Job.delete_related_resources
method optimizes deletion process.The method efficiently deletes labels and attributes, preventing redundant deletions.
801-803
: Modification inJob.delete
method is correct.The method now calls
delete_related_resources
before deletion, ensuring efficient resource management.cvat/apps/engine/views.py (1)
1749-1753
: Ensure the transaction block covers all necessary operations.The transaction block ensures atomicity, but make sure all related operations are included within the block to maintain data integrity.
cvat/apps/engine/views.py
Outdated
segment = instance.segment | ||
super().perform_destroy(instance) | ||
if segment: | ||
segment.delete() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optimize segment deletion logic.
The segment deletion logic can be optimized by checking the existence of the segment before entering the transaction block to avoid unnecessary transactions.
- with transaction.atomic():
- segment = instance.segment
- super().perform_destroy(instance)
- if segment:
- segment.delete()
+ segment = instance.segment
+ if segment:
+ with transaction.atomic():
+ super().perform_destroy(instance)
+ segment.delete()
+ else:
+ super().perform_destroy(instance)
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
segment = instance.segment | |
super().perform_destroy(instance) | |
if segment: | |
segment.delete() | |
segment = instance.segment | |
if segment: | |
with transaction.atomic(): | |
super().perform_destroy(instance) | |
segment.delete() | |
else: | |
super().perform_destroy(instance) |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #8192 +/- ##
==========================================
Coverage ? 83.32%
==========================================
Files ? 388
Lines ? 41396
Branches ? 3856
==========================================
Hits ? 34493
Misses ? 6903
Partials ? 0
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a few minor comments, but overall patch works for me.
@Marishka17 @zhiltsov-max Any more comments? |
Co-authored-by: Maxim Zhiltsov <zhiltsov.max35@gmail.com>
Co-authored-by: Maxim Zhiltsov <zhiltsov.max35@gmail.com>
Quality Gate passedIssues Measures |
Motivation and context
How has this been tested?
Checklist
develop
branch(cvat-canvas,
cvat-core,
cvat-data and
cvat-ui)
License
Feel free to contact the maintainers if that's a concern.
Summary by CodeRabbit
Bug Fixes
Performance Improvements
General Improvements