Skip to content
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

chore: filter the deleted issues for displaying stats #5893

Merged
merged 1 commit into from
Oct 22, 2024

Conversation

NarayanBavisetti
Copy link
Collaborator

@NarayanBavisetti NarayanBavisetti commented Oct 22, 2024

chore:

  • filter the deleted issues for displaying stats

Summary by CodeRabbit

  • New Features

    • Enhanced filtering logic across multiple API endpoints to exclude deleted issues and cycles, improving data integrity and accuracy in responses.
  • Bug Fixes

    • Adjusted query conditions to ensure only non-deleted issues are counted and retrieved in various states (total, completed, cancelled, etc.).
  • Documentation

    • Updated internal documentation to reflect changes in filtering logic and data retrieval processes.

Copy link
Contributor

coderabbitai bot commented Oct 22, 2024

Walkthrough

The changes in this pull request involve multiple modifications across various API endpoints to enhance the filtering logic for issues associated with cycles and modules. Specifically, conditions have been added to ensure that only non-deleted issues are counted or retrieved by checking the deleted_at field for both cycles and modules. This includes updates to methods in several classes, ensuring that operations reflect only active issues, thereby improving data integrity and accuracy in API responses.

Changes

File Path Change Summary
apiserver/plane/api/views/cycle.py Updated CycleAPIEndpoint, CycleArchiveUnarchiveAPIEndpoint, CycleIssueAPIEndpoint, and TransferCycleIssueAPIEndpoint to filter issues by issue_cycle__deleted_at__isnull=True.
apiserver/plane/api/views/module.py Modified ModuleAPIEndpoint and ModuleIssueAPIEndpoint to include issue_module__deleted_at__isnull=True in issue counts and retrieval.
apiserver/plane/app/views/analytic/base.py Enhanced AnalyticsEndpoint to filter issues based on issue_cycle__deleted_at and issue_module__deleted_at.
apiserver/plane/app/views/cycle/archive.py Updated CycleArchiveUnarchiveEndpoint to include checks for issue_cycle__deleted_at__isnull=True in issue counts and estimates.
apiserver/plane/app/views/cycle/base.py Modified CycleViewSet to filter counts and retrievals based on issue_cycle__deleted_at__isnull=True.
apiserver/plane/app/views/cycle/issue.py Updated CycleIssueViewSet to filter non-deleted cycle issues in the list method.
apiserver/plane/app/views/module/archive.py Enhanced ModuleArchiveUnarchiveEndpoint to filter issues by issue_module__deleted_at__isnull=True in various counts and estimates.
apiserver/plane/app/views/module/base.py Modified ModuleViewSet to include filtering for issue_module__deleted_at__isnull=True in issue counts and retrievals.
apiserver/plane/app/views/module/issue.py Updated ModuleIssueViewSet to filter out deleted module issues in the get_queryset method.
apiserver/plane/app/views/workspace/cycle.py Updated WorkspaceCyclesEndpoint to include issue_cycle__deleted_at__isnull=True in issue counts.
apiserver/plane/app/views/workspace/module.py Modified WorkspaceModulesEndpoint to filter counts by issue_module__deleted_at__isnull=True.
apiserver/plane/bgtasks/analytic_plot_export.py Updated get_module_details and get_cycle_details functions to exclude deleted modules and cycles.
apiserver/plane/utils/analytics_plot.py Enhanced burndown_plot function to filter out deleted issues for cycle and module queries.

Possibly related PRs

Suggested labels

⚙️backend, 🌟improvement

Suggested reviewers

  • pablohashescobar

🐇 In the fields where we hop and play,
Non-deleted issues lead the way.
With cycles and modules, clear and bright,
Our data shines, a pure delight!
Filtering out the lost and gone,
In our API, the truth lives on! 🌼


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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

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: 9

🧹 Outside diff range and nitpick comments (7)
apiserver/plane/app/views/workspace/cycle.py (1)

Line range hint 36-96: Overall assessment: Consistent and effective implementation of deleted issue filtering.

The changes in this file consistently apply the issue_cycle__deleted_at__isnull=True filter across all issue annotations, effectively implementing the PR objective of filtering deleted issues for accurate statistics. The implementation is clean and doesn't introduce any new complexity.

Consider refactoring the repeated filter condition into a reusable Q object to reduce code duplication. For example:

from django.db.models import Q

non_deleted_issue_filter = Q(
    issue_cycle__issue__archived_at__isnull=True,
    issue_cycle__issue__is_draft=False,
    issue_cycle__issue__deleted_at__isnull=True,
    issue_cycle__deleted_at__isnull=True,
)

# Then use it in annotations like this:
total_issues=Count("issue_cycle", filter=non_deleted_issue_filter)

This refactoring would make the code more DRY and easier to maintain in the future.

apiserver/plane/app/views/workspace/module.py (2)

48-48: Approved: Filtering out deleted issues improves data accuracy.

The addition of issue_module__deleted_at__isnull=True to the filter ensures that only non-deleted issues are counted, which aligns with the PR objective and improves the accuracy of the total issues count.

Consider extracting the common filter conditions into a separate Q object to improve code readability and maintainability. For example:

base_filter = Q(
    issue_module__issue__archived_at__isnull=True,
    issue_module__issue__is_draft=False,
    issue_module__deleted_at__isnull=True,
)

# Then use it in annotations like this:
total_issues=Count("issue_module", filter=base_filter, distinct=True)

This approach would reduce repetition and make it easier to update the filter conditions across all annotations if needed in the future.


Line range hint 1-124: Overall assessment: Consistent and effective implementation of issue filtering.

The changes in this file successfully implement the filtering of deleted issues across all annotations in the WorkspaceModulesEndpoint class. This improvement ensures that the module statistics accurately reflect only active issues, which aligns with the PR objective of enhancing the accuracy of displayed stats.

To further improve the code:

  1. Consider extracting the common filter conditions into a separate Q object to reduce repetition and improve maintainability.
  2. Add a comment explaining the purpose of the issue_module__deleted_at__isnull=True condition to enhance code readability.

Example refactoring:

# Define base filter to exclude deleted and archived issues
base_filter = Q(
    issue_module__issue__archived_at__isnull=True,
    issue_module__issue__is_draft=False,
    issue_module__deleted_at__isnull=True,  # Exclude deleted issues
)

# Use in annotations
total_issues=Count("issue_module", filter=base_filter, distinct=True)
completed_issues=Count("issue_module__issue__state__group", filter=base_filter & Q(issue_module__issue__state__group="completed"), distinct=True)
# ... repeat for other issue states

This refactoring would make the code more maintainable and easier to update if additional filtering criteria are needed in the future.

apiserver/plane/app/views/module/issue.py (1)

61-61: LGTM! Consider adding a comment for clarity.

The addition of issue_module__deleted_at__isnull=True effectively filters out deleted module issues, which aligns with the PR objective. This change is consistent with similar modifications in other files and improves the accuracy of the displayed statistics.

Consider adding a brief comment explaining the purpose of this filter for better code readability:

# Filter out deleted module issues
issue_module__deleted_at__isnull=True,
apiserver/plane/bgtasks/analytic_plot_export.py (1)

Line range hint 172-185: Improvement in data integrity for cycle details

The addition of issue_cycle__deleted_at__isnull=True to the filter conditions is a positive change. This ensures that only active (non-deleted) cycles are included in the query results, which aligns with the PR's objective of filtering out deleted issues for more accurate statistics.

For consistency with the get_module_details function, consider moving the new condition next to the issue_cycle__cycle_id__isnull=False condition:

 def get_cycle_details(slug, filters):
     return (
         Issue.issue_objects.filter(
             workspace__slug=slug,
             **filters,
             issue_cycle__cycle_id__isnull=False,
+            issue_cycle__deleted_at__isnull=True,
         )
-        issue_cycle__deleted_at__isnull=True,
         .distinct("issue_cycle__cycle_id")
         .order_by("issue_cycle__cycle_id")
         .values(
             "issue_cycle__cycle_id",
             "issue_cycle__cycle__name",
         )
     )

This minor adjustment would improve code readability and maintain consistency across similar functions.

apiserver/plane/api/views/module.py (1)

376-379: Approved: Filtering of deleted module issues

The addition of issue_module__deleted_at__isnull=True to the filter ensures that deleted module issues are excluded from the query results, improving data consistency.

Consider combining the new condition with the existing filter for better readability:

Issue.issue_objects.filter(
    issue_module__module_id=module_id,
    issue_module__deleted_at__isnull=True,
)

This minor change doesn't affect functionality but slightly improves code readability.

apiserver/plane/app/views/module/archive.py (1)

Line range hint 60-195: Consider refactoring repeated filters to adhere to the DRY principle

The issue_module__deleted_at__isnull=True filter is added multiple times across different querysets. Refactoring this filter into a variable or a reusable Q object can improve code maintainability and readability.

You can define a Q object at the beginning of the method:

deleted_module_filter = Q(issue_module__deleted_at__isnull=True)

And then use it in your querysets:

Issue.issue_objects.filter(
    state__group="cancelled",
    issue_module__module_id=OuterRef("pk"),
).filter(deleted_module_filter)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 295f094 and fbb19a9.

📒 Files selected for processing (13)
  • apiserver/plane/api/views/cycle.py (25 hunks)
  • apiserver/plane/api/views/module.py (13 hunks)
  • apiserver/plane/app/views/analytic/base.py (2 hunks)
  • apiserver/plane/app/views/cycle/archive.py (11 hunks)
  • apiserver/plane/app/views/cycle/base.py (20 hunks)
  • apiserver/plane/app/views/cycle/issue.py (1 hunks)
  • apiserver/plane/app/views/module/archive.py (16 hunks)
  • apiserver/plane/app/views/module/base.py (17 hunks)
  • apiserver/plane/app/views/module/issue.py (1 hunks)
  • apiserver/plane/app/views/workspace/cycle.py (6 hunks)
  • apiserver/plane/app/views/workspace/module.py (6 hunks)
  • apiserver/plane/bgtasks/analytic_plot_export.py (2 hunks)
  • apiserver/plane/utils/analytics_plot.py (6 hunks)
🧰 Additional context used
🔇 Additional comments (53)
apiserver/plane/app/views/workspace/cycle.py (6)

36-36: LGTM: Appropriate filter for non-deleted issues added.

The addition of issue_cycle__deleted_at__isnull=True to the total_issues annotation ensures that only non-deleted issues are counted, which aligns with the PR objective of filtering deleted issues for accurate statistics.


48-48: LGTM: Consistent filter applied to completed issues.

The addition of issue_cycle__deleted_at__isnull=True to the completed_issues annotation is consistent with the previous change and ensures that only non-deleted completed issues are counted.


60-60: LGTM: Consistent filter applied to cancelled issues.

The addition of issue_cycle__deleted_at__isnull=True to the cancelled_issues annotation maintains consistency with the previous changes and ensures that only non-deleted cancelled issues are counted.


72-72: LGTM: Consistent filter applied to started issues.

The addition of issue_cycle__deleted_at__isnull=True to the started_issues annotation continues the pattern of consistency across all annotations and ensures that only non-deleted started issues are counted.


84-84: LGTM: Consistent filter applied to unstarted issues.

The addition of issue_cycle__deleted_at__isnull=True to the unstarted_issues annotation maintains the consistency observed in all previous annotations and ensures that only non-deleted unstarted issues are counted.


96-96: LGTM: Consistent filter applied to backlog issues, completing the pattern.

The addition of issue_cycle__deleted_at__isnull=True to the backlog_issues annotation completes the pattern of consistency across all annotations and ensures that only non-deleted backlog issues are counted.

apiserver/plane/app/views/workspace/module.py (5)

60-60: Approved: Consistent filtering for completed issues.

The addition of issue_module__deleted_at__isnull=True to the filter for completed issues is consistent with the change made to the total issues count. This ensures that only non-deleted completed issues are included in the count, maintaining data integrity across different issue states.


72-72: Approved: Consistent filtering for cancelled issues.

The addition of issue_module__deleted_at__isnull=True to the filter for cancelled issues maintains consistency with the changes made to other issue state counts. This ensures that only non-deleted cancelled issues are included in the count, preserving data accuracy across all issue states.


84-84: Approved: Consistent filtering for started issues.

The addition of issue_module__deleted_at__isnull=True to the filter for started issues maintains consistency with the changes made to other issue state counts. This ensures that only non-deleted started issues are included in the count, maintaining data integrity across all issue states.


96-96: Approved: Consistent filtering for unstarted issues.

The addition of issue_module__deleted_at__isnull=True to the filter for unstarted issues maintains consistency with the changes made to other issue state counts. This ensures that only non-deleted unstarted issues are included in the count, preserving data accuracy across all issue states.


108-108: Approved: Consistent filtering for backlog issues and overall improvement.

The addition of issue_module__deleted_at__isnull=True to the filter for backlog issues completes the consistent application of this condition across all issue state counts. This change, along with the similar modifications to other annotations, significantly improves the accuracy of module statistics by ensuring that deleted issues are excluded from all counts.

These changes collectively address the PR objective of filtering out deleted issues for displaying accurate stats. The implementation is thorough and consistent, covering all relevant issue states (total, completed, cancelled, started, unstarted, and backlog).

apiserver/plane/utils/analytics_plot.py (7)

145-145: LGTM: Filtering out deleted cycle issues

This change ensures that only non-deleted issues are considered when calculating estimates for cycles, which aligns with the PR objective of filtering out deleted issues for accurate stats.


157-157: LGTM: Filtering out deleted module issues

This change ensures that only non-deleted issues are considered when calculating estimates for modules, which is consistent with the previous change and aligns with the PR objective of filtering out deleted issues for accurate stats.


184-184: LGTM: Filtering out deleted cycle issues for completed issues distribution

This change ensures that only non-deleted issues are considered when calculating the completed issues distribution for cycles, which is consistent with the previous changes and aligns with the PR objective of filtering out deleted issues for accurate stats.


198-198: LGTM: Filtering out deleted cycle issues for non-point based completed issues distribution

This change ensures that only non-deleted issues are considered when calculating the completed issues distribution for cycles (non-point based), which is consistent with the previous changes and aligns with the PR objective of filtering out deleted issues for accurate stats.


224-224: LGTM: Filtering out deleted module issues for completed issues distribution

This change ensures that only non-deleted issues are considered when calculating the completed issues distribution for modules, which is consistent with the previous changes and aligns with the PR objective of filtering out deleted issues for accurate stats.


238-238: LGTM: Filtering out deleted module issues for non-point based completed issues distribution

This change ensures that only non-deleted issues are considered when calculating the completed issues distribution for modules (non-point based), which is consistent with the previous changes and aligns with the PR objective of filtering out deleted issues for accurate stats.


Line range hint 145-238: Summary: Consistent implementation of deleted issue filtering

The changes in this file consistently implement filtering of deleted issues across various queries related to cycles and modules. This improvement ensures that analytics and plots are based on active issues only, enhancing the accuracy of the displayed statistics. The implementation is correct and aligns well with the PR objective.

Great job on maintaining consistency throughout the file!

apiserver/plane/app/views/module/issue.py (1)

61-61: Positive impact on the entire viewset

The addition of issue_module__deleted_at__isnull=True in the get_queryset method ensures that all operations performed by other methods in this viewset (such as list, create_module_issues, create_issue_modules, and destroy) will now work only with non-deleted module issues. This change maintains consistency across the entire viewset and aligns with the PR objective of filtering out deleted issues for displaying stats.

apiserver/plane/app/views/cycle/issue.py (1)

93-96: LGTM! Important filter added for non-deleted cycle issues.

The addition of issue_cycle__deleted_at__isnull=True to the filter conditions is a crucial improvement. This ensures that only active (non-deleted) cycle issues are included in the queryset, which aligns perfectly with the PR objective of filtering out deleted issues for accurate stat display.

This change enhances data integrity and consistency across the application, particularly when retrieving and displaying cycle-related information.

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

Line range hint 158-169: Improvement in data integrity for module details

The addition of issue_module__deleted_at__isnull=True to the filter conditions is a positive change. This ensures that only active (non-deleted) modules are included in the query results, which aligns with the PR's objective of filtering out deleted issues for more accurate statistics.


Line range hint 1-585: Overall improvement in data integrity for analytics

The changes made to get_module_details and get_cycle_details functions are consistent with the PR's objective of filtering out deleted issues for more accurate statistics. These modifications ensure that only active (non-deleted) modules and cycles are included in the query results, which will lead to more accurate analytics and exports.

These changes are part of a larger effort to enhance data integrity across the codebase, as seen in similar modifications to other API endpoints and classes mentioned in the AI-generated summary. The consistency in approach across different parts of the system is commendable.

No other parts of this file were modified, and the changes maintain backward compatibility by not altering function signatures or return values. This focused approach minimizes the risk of unintended side effects while achieving the desired improvement in data accuracy.

apiserver/plane/app/views/analytic/base.py (3)

174-174: LGTM: Filtering out deleted cycles

This change ensures that only non-deleted cycles are included in the analytics by adding the condition issue_cycle__deleted_at__isnull=True. This aligns with the PR objective of filtering out deleted issues for more accurate stat display.


193-193: LGTM: Filtering out deleted modules

This change ensures that only non-deleted modules are included in the analytics by adding the condition issue_module__deleted_at__isnull=True. This is consistent with the PR objective of filtering out deleted issues for more accurate stat display.


Line range hint 174-193: Summary: Improved data integrity for analytics

The changes in this file enhance the AnalyticsEndpoint class by filtering out deleted cycles and modules from the analytics data. This improvement ensures more accurate statistics by only considering active data. The modifications are consistent with the PR objectives and similar changes in other files, contributing to a more robust analytics system.

apiserver/plane/api/views/module.py (3)

74-74: Excellent addition of deleted issue filter

The new condition issue_module__deleted_at__isnull=True has been consistently added to all issue count annotations. This change ensures that deleted issues are excluded from various counts (total, completed, cancelled, started, unstarted, backlog), improving the accuracy of module statistics.

Also applies to: 86-86, 98-98, 110-110, 122-122, 134-134


564-564: Consistent implementation of deleted issue filtering for archived modules

The addition of issue_module__deleted_at__isnull=True to all issue count annotations in the ModuleArchiveUnarchiveAPIEndpoint is consistent with the changes made in ModuleAPIEndpoint. This ensures that archived modules also exclude deleted issues from their counts, maintaining data accuracy across the entire module lifecycle.

Also applies to: 576-576, 588-588, 600-600, 612-612, 624-624


Line range hint 1-668: Summary: Effective implementation of deleted issue filtering

The changes in this file consistently implement filtering of deleted issues across different classes and methods. This improves data accuracy for module statistics, query results, and archived modules. The modifications align well with the PR objective and maintain consistency throughout the file.

Key improvements:

  1. Accurate issue counts in ModuleAPIEndpoint
  2. Consistent query results in ModuleIssueAPIEndpoint
  3. Proper handling of archived modules in ModuleArchiveUnarchiveAPIEndpoint

These changes enhance the overall data integrity of the module-related operations without introducing any apparent negative impacts on existing functionality.

apiserver/plane/app/views/cycle/archive.py (4)

51-51: Consistent filtering of non-deleted issues

The addition of issue_cycle__deleted_at__isnull=True to various querysets in the get_queryset method ensures that only non-deleted issues are considered when calculating estimates and counts. This change improves data accuracy and consistency.

Also applies to: 66-66, 81-81, 96-96, 111-111, 125-125


357-357: Consistent filtering in get method and distribution calculations

The addition of issue_cycle__deleted_at__isnull=True to the querysets in the get method and distribution calculations ensures that only non-deleted issues are considered. This change maintains consistency with the modifications in the get_queryset method and improves the overall data integrity of the API response.

Also applies to: 412-412, 470-470, 526-526, 597-597


Line range hint 51-597: Overall improvement in data accuracy for cycle statistics

The changes made to this file consistently implement filtering of deleted issues across all relevant queries in the CycleArchiveUnarchiveEndpoint class. This enhancement aligns well with the PR objectives and should significantly improve the accuracy of displayed cycle statistics by excluding deleted issues from all calculations and data retrievals.

Some key points:

  1. Consistent application of issue_cycle__deleted_at__isnull=True filter across different querysets.
  2. Improved data integrity in estimate calculations, issue counts, and distribution data.
  3. Enhanced accuracy in API responses for cycle-related information.

These changes contribute to a more reliable and accurate representation of cycle data in the application.


Line range hint 1-697: LGTM! Approved changes for improved cycle data accuracy

The modifications in this file are well-implemented and consistent throughout the CycleArchiveUnarchiveEndpoint class. They effectively address the PR objective of filtering deleted issues for displaying stats. The changes improve data accuracy and integrity without introducing any significant performance or security concerns.

Key improvements:

  1. Consistent filtering of deleted issues across all relevant queries.
  2. Enhanced accuracy in cycle statistics, estimates, and distribution data.
  3. Improved API response integrity for cycle-related information.

These changes are approved and ready for merging.

apiserver/plane/app/views/module/base.py (8)

88-89: LGTM: Filtering out deleted issues for cancelled count.

This change correctly ensures that only non-deleted issues are counted as cancelled issues, aligning with the PR objective.


98-99: LGTM: Filtering out deleted issues for completed count.

This change correctly ensures that only non-deleted issues are counted as completed issues, maintaining consistency with the PR objective.


108-109: LGTM: Filtering out deleted issues for started count.

This change correctly ensures that only non-deleted issues are counted as started issues, maintaining consistency with the PR objective and previous changes.


118-119: LGTM: Consistent filtering of deleted issues across all issue counts.

These changes correctly ensure that only non-deleted issues are counted for unstarted, backlog, and total issues. This maintains consistency with the PR objective and previous changes.

Also applies to: 128-129, 137-138


148-149: LGTM: Consistent filtering of deleted issues for estimate point calculations.

These changes correctly ensure that only non-deleted issues are considered for various estimate point calculations. This maintains consistency with the PR objective and previous changes across different issue states and total estimates.

Also applies to: 163-164, 178-179, 193-194, 208-209, 223-224


463-464: LGTM: Filtering out deleted sub-issues in retrieve method.

This change correctly ensures that only non-deleted sub-issues are retrieved in the retrieve method, maintaining consistency with the PR objective and previous changes.


493-494: LGTM: Consistent filtering of deleted issues for distribution calculations.

These changes correctly ensure that only non-deleted issues are considered for various distribution calculations in the retrieve method. This maintains consistency with the PR objective and previous changes across different types of distributions (assignees and labels).

Also applies to: 559-560, 611-612, 681-682


Line range hint 1-963: Overall assessment: Comprehensive and consistent implementation of deleted issue filtering.

The changes in this file thoroughly implement the filtering of deleted issues across various queries and methods. This consistent approach ensures that all statistics and retrievals exclude deleted issues, aligning perfectly with the PR objective. The implementation covers issue counts, estimate points, sub-issues, and distribution calculations, providing a comprehensive solution.

apiserver/plane/app/views/module/archive.py (3)

495-495: Confirm that issue counts exclude deleted modules

At line 495, the filter issue_module__deleted_at__isnull=True is added to the assignee distribution queryset. Ensure that this filter correctly excludes issues from deleted modules.


565-565: Confirm that label distributions exclude deleted modules

At line 565, the filter issue_module__deleted_at__isnull=True is added to the label distribution queryset. Verify that the label statistics accurately reflect only active modules.


376-376: Verify that all issue queries include the deleted module filter

Ensure that the issue_module__deleted_at__isnull=True filter is applied in all queries fetching issues to prevent inclusion of deleted modules' issues.

Use the following script to find any missing filters:

#!/bin/bash
# Description: Check for missing deleted_module_filter in Issue queries

# Expected Result: All Issue queries should include the deleted_module_filter
rg -A 5 'Issue\.issue_objects\.filter\(' apiserver/plane/app/views/ | \
grep -B 5 -A 10 'issue_module__module_id' | \
grep -v 'issue_module__deleted_at__isnull=True'
apiserver/plane/api/views/cycle.py (8)

81-81: Correctly excluded deleted issues from counts in CycleAPIEndpoint

The addition of issue_cycle__deleted_at__isnull=True to the filters in the annotations ensures that deleted issues are excluded from the counts of total_issues, completed_issues, cancelled_issues, started_issues, unstarted_issues, and backlog_issues. This aligns with the objective to enhance the accuracy of displayed statistics.

Also applies to: 92-92, 103-103, 114-114, 125-125, 136-136


446-446: Consistently filtered out deleted issues in CycleArchiveUnarchiveAPIEndpoint

By including issue_cycle__deleted_at__isnull=True in the annotations, the counts for archived cycles now accurately reflect only active issues, excluding any that have been deleted.

Also applies to: 457-457, 468-468, 479-479, 490-490, 501-501, 515-515, 526-526


632-635: Ensured only active issues are retrieved in CycleIssueAPIEndpoint

The addition of issue_cycle__deleted_at__isnull=True in the queryset filters ensures that only non-deleted issues are listed when fetching issues related to a cycle. This enhances data integrity and user experience.


832-832: Excluded deleted issues during issue transfer in TransferCycleIssueAPIEndpoint

Including issue_cycle__deleted_at__isnull=True in the filters when annotating issue counts ensures that deleted issues are not considered during the transfer process between cycles.

Also applies to: 843-843, 854-854, 865-865, 876-876, 887-887


904-904: Accurate estimate calculations by excluding deleted issues

Adding issue_cycle__deleted_at__isnull=True to the filters ensures that estimate calculations for assignees are based solely on active issues, improving the accuracy of the assignee estimate data.


980-980: Corrected label estimate distribution to exclude deleted issues

By filtering out deleted issues using issue_cycle__deleted_at__isnull=True, the label estimate distribution now accurately represents estimates from active issues only.


1042-1042: Improved assignee distribution accuracy

The inclusion of issue_cycle__deleted_at__isnull=True ensures that the assignee distribution computations exclude deleted issues, providing more precise analytics.


1121-1121: Updated label distribution to reflect active issues

By adding issue_cycle__deleted_at__isnull=True to the filters, the label distribution now correctly accounts for only non-deleted issues, enhancing the reliability of the data.

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

1374-1374: Check for missing deletion filters in issue analytics

When generating assignee distributions for issues, verify that the filters include issue_cycle__issue__deleted_at__isnull=True to exclude deleted issues.

Run this script to identify potential omissions:

#!/bin/bash
# Description: Identify issue analytics without proper deletion checks.

# Expected: All issue analytics should filter out deleted issues.

# Search for analytics queries missing `issue__deleted_at__isnull=True`
rg -A5 'issue_objects\.filter\(' | rg 'issue_cycle__cycle_id=' | rg -v 'issue__deleted_at__isnull=True'

682-682: Verify consistency in issue filtering

While filtering issues for estimate calculations, ensure that both issue_cycle__issue__deleted_at__isnull=True and issue_cycle__deleted_at__isnull=True are included to exclude deleted issues and issue cycles.

Run the following script to check for consistency across the codebase:

✅ Verification successful

Consistency in issue filtering verified.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for filters missing issue deletion checks.

# Expected: All querysets involving issues should include both deletion checks.

# Search for issue querysets missing `issue__deleted_at__isnull=True`
rg -A5 'Issue\.issue_objects\.filter\(' | rg -v 'issue__deleted_at__isnull=True'

Length of output: 3326

@@ -337,6 +349,7 @@ def get(self, request, slug, project_id, pk=None):
project_id=self.kwargs.get("project_id"),
parent__isnull=False,
issue_module__module_id=pk,
issue_module__deleted_at__isnull=True,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Inconsistent Application of deleted_at Filter Detected

The following queries are missing the issue_module__deleted_at__isnull=True filter:

  • apiserver/plane/app/views/module/base.py
  • apiserver/plane/app/views/module/archive.py
  • apiserver/plane/app/views/module/issue.py
  • apiserver/plane/app/views/analytic/base.py

Please ensure that all Issue.issue_objects.filter queries include the issue_module__deleted_at__isnull=True filter to maintain data integrity.

🔗 Analysis chain

Ensure consistency in filtering deleted modules

In line 352, the filter issue_module__deleted_at__isnull=True is added. Verify that all related queries consistently apply this filter to maintain data integrity.

Run the following script to check for any occurrences where the filter might be missing:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find Issue queries without the deleted_module_filter

# Expected Result: No Issue queries lacking the deleted_module_filter
rg -A 5 'Issue\.issue_objects\.filter\(' apiserver/plane/app/views/ | \
grep -B 5 -A 10 'issue_module__module_id' | \
grep -v 'issue_module__deleted_at__isnull=True'

Length of output: 17153

@@ -102,7 +102,7 @@ def get_queryset(self):
filter=Q(
issue_cycle__issue__archived_at__isnull=True,
issue_cycle__issue__is_draft=False,
issue_cycle__issue__deleted_at__isnull=True,
issue_cycle__deleted_at__isnull=True,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Consider adding issue deletion check to the filter

In the total_issues annotation, you've added a filter for issue_cycle__deleted_at__isnull=True. To ensure that deleted issues themselves are also excluded, consider adding issue_cycle__issue__deleted_at__isnull=True to the filter conditions.

Apply this diff to include the issue deletion check:

                             issue_cycle__issue__archived_at__isnull=True,
                             issue_cycle__issue__is_draft=False,
+                            issue_cycle__issue__deleted_at__isnull=True,
                             issue_cycle__deleted_at__isnull=True,
📝 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.

Suggested change
issue_cycle__deleted_at__isnull=True,
issue_cycle__issue__archived_at__isnull=True,
issue_cycle__issue__is_draft=False,
issue_cycle__issue__deleted_at__isnull=True,
issue_cycle__deleted_at__isnull=True,

@@ -1220,6 +1238,7 @@
issue_cycle__issue__archived_at__isnull=True,
issue_cycle__issue__is_draft=False,
issue_cycle__issue__deleted_at__isnull=True,
issue_cycle__deleted_at__isnull=True,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Ensure deleted issues are excluded in cycle analytics

In the CycleAnalyticsEndpoint, include issue_cycle__issue__deleted_at__isnull=True in the filters to ensure accurate analytics by excluding deleted issues.

Apply this diff:

                             issue_cycle__issue__deleted_at__isnull=True,
+                            issue_cycle__deleted_at__isnull=True,

Committable suggestion was skipped due to low confidence.

@@ -1408,6 +1430,7 @@
label_distribution = (
Issue.issue_objects.filter(
issue_cycle__cycle_id=cycle_id,
issue_cycle__deleted_at__isnull=True,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Include issue deletion check in label distribution

In the label distribution calculation, ensure that deleted issues are excluded by adding issue_cycle__issue__deleted_at__isnull=True to the filters.

Update the filter as follows:

                         issue_cycle__cycle_id=cycle_id,
+                        issue_cycle__issue__deleted_at__isnull=True,
                         issue_cycle__deleted_at__isnull=True,
📝 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.

Suggested change
issue_cycle__deleted_at__isnull=True,
issue_cycle__cycle_id=cycle_id,
issue_cycle__issue__deleted_at__isnull=True,
issue_cycle__deleted_at__isnull=True,

@@ -114,7 +114,7 @@
issue_cycle__issue__state__group="completed",
issue_cycle__issue__archived_at__isnull=True,
issue_cycle__issue__is_draft=False,
issue_cycle__issue__deleted_at__isnull=True,
issue_cycle__deleted_at__isnull=True,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Include issue deletion check in completed issues filter

When annotating completed_issues, consider adding issue_cycle__issue__deleted_at__isnull=True to exclude deleted issues from the count.

Apply this diff:

                             issue_cycle__issue__state__group="completed",
                             issue_cycle__issue__archived_at__isnull=True,
                             issue_cycle__issue__is_draft=False,
+                            issue_cycle__issue__deleted_at__isnull=True,
                             issue_cycle__deleted_at__isnull=True,
📝 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.

Suggested change
issue_cycle__deleted_at__isnull=True,
issue_cycle__issue__state__group="completed",
issue_cycle__issue__archived_at__isnull=True,
issue_cycle__issue__is_draft=False,
issue_cycle__issue__deleted_at__isnull=True,
issue_cycle__deleted_at__isnull=True,

@@ -1074,6 +1085,7 @@
Issue.issue_objects.filter(
estimate_point__estimate__type="points",
issue_cycle__cycle_id=cycle_id,
issue_cycle__deleted_at__isnull=True,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add issue deletion check to estimate aggregation

In the CycleProgressEndpoint, when aggregating estimates, consider adding issue_cycle__issue__deleted_at__isnull=True to exclude deleted issues from the calculations.

Proposed update:

                     issue_cycle__cycle_id=cycle_id,
+                    issue_cycle__issue__deleted_at__isnull=True,
                     issue_cycle__deleted_at__isnull=True,
📝 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.

Suggested change
issue_cycle__deleted_at__isnull=True,
issue_cycle__cycle_id=cycle_id,
issue_cycle__issue__deleted_at__isnull=True,
issue_cycle__deleted_at__isnull=True,

@@ -601,6 +602,7 @@
filter=Q(
issue_cycle__issue__archived_at__isnull=True,
issue_cycle__issue__is_draft=False,
issue_cycle__deleted_at__isnull=True,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Ensure deleted issues are excluded in total issues count

In the TransferCycleIssueEndpoint, when annotating total_issues, consider adding issue_cycle__issue__deleted_at__isnull=True to exclude deleted issues from the total count.

Proposed change:

                             issue_cycle__issue__archived_at__isnull=True,
                             issue_cycle__issue__is_draft=False,
+                            issue_cycle__issue__deleted_at__isnull=True,
                             issue_cycle__deleted_at__isnull=True,

Committable suggestion was skipped due to low confidence.

@@ -612,6 +614,7 @@
issue_cycle__issue__archived_at__isnull=True,
issue_cycle__issue__is_draft=False,
issue_cycle__issue__deleted_at__isnull=True,
issue_cycle__deleted_at__isnull=True,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Include issue deletion check in completed issues count

For completed_issues annotation, add issue_cycle__issue__deleted_at__isnull=True to ensure deleted issues are not counted.

Apply this diff:

                             issue_cycle__issue__state__group="completed",
                             issue_cycle__issue__archived_at__isnull=True,
                             issue_cycle__issue__is_draft=False,
                             issue_cycle__issue__deleted_at__isnull=True,
+                            issue_cycle__deleted_at__isnull=True,

Committable suggestion was skipped due to low confidence.

@@ -398,6 +398,7 @@
project_id=self.kwargs.get("project_id"),
parent__isnull=False,
issue_cycle__cycle_id=pk,
issue_cycle__deleted_at__isnull=True,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add issue deletion check to sub-issues filter

In the retrieve method, when fetching sub_issues, ensure that deleted issues are excluded by adding deleted_at__isnull=True to the filter.

Update the filter condition as follows:

                     sub_issues=Issue.issue_objects.filter(
                         project_id=self.kwargs.get("project_id"),
                         parent__isnull=False,
                         issue_cycle__cycle_id=pk,
+                        deleted_at__isnull=True,
                         issue_cycle__deleted_at__isnull=True,
                     )

Committable suggestion was skipped due to low confidence.

@pushya22 pushya22 merged commit 6df9809 into preview Oct 22, 2024
14 of 15 checks passed
@pushya22 pushya22 deleted the chore/stats-cycle-module branch October 22, 2024 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants