Skip to content

Comments

[WEB-2092] chore: soft delete operation#5244

Merged
sriramveeraghanta merged 5 commits intopreviewfrom
chore/soft-delete-opration
Jul 29, 2024
Merged

[WEB-2092] chore: soft delete operation#5244
sriramveeraghanta merged 5 commits intopreviewfrom
chore/soft-delete-opration

Conversation

@NarayanBavisetti
Copy link
Collaborator

@NarayanBavisetti NarayanBavisetti commented Jul 26, 2024

Issue Link: WEB-2092

Summary by CodeRabbit

  • New Features

    • Introduced soft deletion capabilities across multiple models, allowing for better data management and recovery options.
    • Enhanced the notification system by scheduling automated hard deletions for outdated records.
  • Bug Fixes

    • Adjusted the filtering logic in issue queries to exclude soft-deleted items, ensuring users only see active issues.
  • Deprecations

    • Marked several classes as deprecated with plans for future removal, guiding users towards updated implementations.
  • Chores

    • Added scheduled tasks for routine database cleanup to improve application performance and data integrity.

@NarayanBavisetti NarayanBavisetti added ⚙️backend 🔄migrations Contains Migration changes labels Jul 26, 2024
@NarayanBavisetti NarayanBavisetti added this to the v0.23-dev milestone Jul 26, 2024
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 26, 2024

Walkthrough

This update enhances the application’s handling of soft deletions by introducing a deleted_at field across multiple models and updating relevant views and tasks. The added functionality allows for improved data management, enabling the application to track deleted records without permanent removal. Additionally, some classes have been marked for deprecation, signaling a shift in the codebase towards cleaner, more maintainable practices.

Changes

Files Change Summary
apiserver/plane/app/views/issue/base.py Added deleted_at field handling in get and create methods to manage soft-deleted issues.
apiserver/plane/bgtasks/deletion_task.py Introduced functions for soft and hard deletion of related objects, leveraging async capabilities.
apiserver/plane/bgtasks/notification_task.py Removed notification handling for deleted issues, altering notification processing behavior.
apiserver/plane/celery.py Added daily scheduled task for hard deletion of stale records.
apiserver/plane/db/migrations/0073_analyticview... Added deleted_at field to over 100 models for soft deletion functionality.
apiserver/plane/db/mixins.py Introduced SoftDeletionManager and SoftDeleteModel for managing soft deletions across models.
apiserver/plane/db/models/cycle.py Deprecated CycleFavorite class with a notice for future removal.
apiserver/plane/db/models/issue.py Updated get_queryset to exclude soft-deleted issues from results.
apiserver/plane/db/models/module.py Deprecated ModuleFavorite class with a notice for future removal.
apiserver/plane/db/models/page.py Deprecated PageBlock and PageFavorite classes with a notice for future removal.
apiserver/plane/db/models/project.py Deprecated ProjectFavorite class with a notice for future removal.
apiserver/plane/db/models/view.py Deprecated GlobalView and IssueViewFavorite classes with a notice for future removal.
apiserver/plane/license/migrations/0004_changelog... Added deleted_at field to several license-related models for soft deletion functionality.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant API
    participant Database
    participant TaskQueue

    User->>API: Create Issue
    API->>Database: Save Issue with "deleted_at" = null
    API->>User: Return Issue

    User->>API: Soft Delete Issue
    API->>Database: Update Issue with current timestamp in "deleted_at"
    API->>TaskQueue: Queue soft deletion of related objects
Loading

🐰 In fields of code we hop and play,
With deleted_at, we keep stale fears at bay.
Softly we delete, yet hold on tight,
For days of old can spring back to light!
Hop, skip, and jump to data's delight! 🌼


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?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@NarayanBavisetti NarayanBavisetti changed the title chore: soft delete opration [WEB-2092] chore: soft delete operation Jul 26, 2024
@NarayanBavisetti NarayanBavisetti marked this pull request as ready for review July 26, 2024 13:56
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

Outside diff range, codebase verification and nitpick comments (3)
apiserver/plane/db/models/cycle.py (1)

119-119: Enhance deprecation notice.

Consider adding a specific version number or date for removal to make the deprecation notice more actionable.

-  # DEPRECATED TODO: - Remove in next release
+  # DEPRECATED TODO: - Remove in next release (v1.2.0 or by 2024-12-31)
apiserver/plane/db/models/view.py (2)

Line range hint 44-44:
Enhance deprecation notice.

Consider adding a specific version number or date for removal to make the deprecation notice more actionable.

-  # DEPRECATED TODO: - Remove in next release
+  # DEPRECATED TODO: - Remove in next release (v1.2.0 or by 2024-12-31)

144-144: Enhance deprecation notice.

Consider adding a specific version number or date for removal to make the deprecation notice more actionable.

-  # DEPRECATED TODO: - Remove in next release
+  # DEPRECATED TODO: - Remove in next release (v1.2.0 or by 2024-12-31)
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2c60967 and 9eab91e.

Files selected for processing (13)
  • apiserver/plane/app/views/issue/base.py (2 hunks)
  • apiserver/plane/bgtasks/deletion_task.py (1 hunks)
  • apiserver/plane/bgtasks/notification_task.py (1 hunks)
  • apiserver/plane/celery.py (1 hunks)
  • apiserver/plane/db/migrations/0073_analyticview_deleted_at_apiactivitylog_deleted_at_and_more.py (1 hunks)
  • apiserver/plane/db/mixins.py (2 hunks)
  • apiserver/plane/db/models/cycle.py (1 hunks)
  • apiserver/plane/db/models/issue.py (1 hunks)
  • apiserver/plane/db/models/module.py (1 hunks)
  • apiserver/plane/db/models/page.py (2 hunks)
  • apiserver/plane/db/models/project.py (1 hunks)
  • apiserver/plane/db/models/view.py (2 hunks)
  • apiserver/plane/license/migrations/0004_changelog_deleted_at_instance_deleted_at_and_more.py (1 hunks)
Files skipped from review due to trivial changes (2)
  • apiserver/plane/db/models/module.py
  • apiserver/plane/db/models/project.py
Additional comments not posted (18)
apiserver/plane/license/migrations/0004_changelog_deleted_at_instance_deleted_at_and_more.py (1)

1-32: Migration file looks good.

The migration file correctly adds a deleted_at field to multiple models. Ensure that the corresponding models and fields are correctly defined in the models.py file.

apiserver/plane/celery.py (1)

39-42: New scheduled task configuration looks good.

The new task "check-every-day-to-delete-hard-delete" is correctly added to the task scheduling dictionary and is scheduled to run daily at midnight.

apiserver/plane/db/mixins.py (4)

46-48: SoftDeletionManager class looks good.

The get_queryset method correctly filters out soft-deleted records by checking if the deleted_at field is null.


51-64: SoftDeleteModel class looks good.

The deleted_at field is correctly defined and the class is marked as abstract.


66-81: Delete method looks good.

The delete method correctly handles soft deletion by setting the deleted_at timestamp and saving the instance. It also triggers the soft_delete_related_objects task for related objects. The hard delete option is also correctly handled.


84-87: AuditModel class looks good.

The class correctly inherits from SoftDeleteModel, incorporating the soft deletion functionality.

apiserver/plane/db/models/cycle.py (1)

119-119: Deprecation notice approved.

The deprecation notice is clear and indicates the class should be removed in the next release.

apiserver/plane/db/models/view.py (2)

Line range hint 44-44:
Deprecation notice approved.

The deprecation notice is clear and indicates the class should be removed in the next release.


144-144: Deprecation notice approved.

The deprecation notice is clear and indicates the class should be removed in the next release.

apiserver/plane/bgtasks/deletion_task.py (2)

10-31: Soft delete function approved.

The function correctly performs a soft delete on related objects.


40-158: Hard delete function approved.

The function correctly performs a hard delete on objects that have been soft deleted for more than 30 days.

apiserver/plane/db/models/page.py (2)

122-122: Deprecation Notice: PageBlock

The PageBlock class has been marked as deprecated. Ensure that any dependencies on this class are refactored before the next release.


179-179: Deprecation Notice: PageFavorite

The PageFavorite class has been marked as deprecated. Ensure that any dependencies on this class are refactored before the next release.

apiserver/plane/app/views/issue/base.py (2)

169-169: Verify the handling of deleted_at field.

The deleted_at field has been added to the fields being retrieved. Ensure that this field is correctly handled in the rest of the codebase, particularly in filtering and business logic.

Verification successful

The deleted_at field is handled correctly.

The deleted_at field is integrated into the filtering and business logic, as evidenced by its presence in various parts of the codebase, including model definitions and filtering conditions.

  • apiserver/plane/db/mixins.py
  • apiserver/plane/db/models/issue.py
  • apiserver/plane/bgtasks/deletion_task.py
  • Multiple migration files
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the handling of `deleted_at` field in the codebase.

# Test: Search for the usage of `deleted_at` field. Expect: Proper handling in filtering and business logic.
rg --type python -A 5 $'deleted_at'

Length of output: 65


Script:

#!/bin/bash
# Description: Verify the handling of `deleted_at` field in the codebase.

# Test: Search for the usage of `deleted_at` field. Expect: Proper handling in filtering and business logic.
rg --glob '*.py' -A 5 'deleted_at'

Length of output: 67879


404-404: Verify the handling of deleted_at field.

The deleted_at field has been added to the fields being returned. Ensure that this field is correctly handled in the rest of the codebase, particularly in filtering and business logic.

Verification successful

The deleted_at field is properly handled in the codebase.

The deleted_at field is integrated across multiple files, including migrations, models, mixins, and background tasks. It is used in filtering logic and soft deletion mechanisms, confirming its correct usage.

  • apiserver/plane/db/mixins.py: Soft delete mechanism.
  • apiserver/plane/db/models/issue.py: Filtering logic.
  • apiserver/plane/bgtasks/deletion_task.py: Background task handling.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the handling of `deleted_at` field in the codebase.

# Test: Search for the usage of `deleted_at` field. Expect: Proper handling in filtering and business logic.
rg --type python -A 5 $'deleted_at'

Length of output: 65


Script:

#!/bin/bash
# Description: Verify the handling of `deleted_at` field in the codebase.

# Test: Search for the usage of `deleted_at` field. Expect: Proper handling in filtering and business logic.
rg --type py -A 5 $'deleted_at'

Length of output: 67875

apiserver/plane/bgtasks/notification_task.py (1)

Line range hint 138-138:
Verify the impact of removing "issue.activity.deleted" from the list of types being checked.

The removal of "issue.activity.deleted" from the list of types being checked may affect the handling of notifications for deleted issues. Ensure that this change aligns with the application's requirements and does not introduce any unintended behavior.

apiserver/plane/db/migrations/0073_analyticview_deleted_at_apiactivitylog_deleted_at_and_more.py (1)

13-421: LGTM!

The migration operations correctly add a deleted_at field to multiple models, aligning with the objective of implementing soft delete functionality.

apiserver/plane/db/models/issue.py (1)

92-92: LGTM!

The added filter condition .filter(deleted_at__isnull=True) ensures that only issues that are not marked as deleted are included in the queryset, aligning with the objective of implementing soft delete functionality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

⚙️backend 🔄migrations Contains Migration changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants