Skip to content

[WEB-2020] chore: display cross project issue relations#5186

Merged
sriramveeraghanta merged 2 commits intopreviewfrom
chore/issue-relations
Jul 22, 2024
Merged

[WEB-2020] chore: display cross project issue relations#5186
sriramveeraghanta merged 2 commits intopreviewfrom
chore/issue-relations

Conversation

@NarayanBavisetti
Copy link
Collaborator

@NarayanBavisetti NarayanBavisetti commented Jul 22, 2024

chore:

  • Display cross-project issue relations so that issues that are blocked, blocked by, related to, or duplicated will now be able to show issues from different projects as well.

Issue Link: WEB-2020

Summary by CodeRabbit

  • Bug Fixes

    • Streamlined the querying process for issue relations, improving efficiency.
  • Refactor

    • Simplified the logic within the issue relation management, enhancing readability and maintainability.

These changes should lead to a more intuitive experience when managing issue relations within the application.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 22, 2024

Walkthrough

The recent changes refactor the IssueRelationViewSet class by removing the get_queryset method, which centralizes the logic for building the issue queryset within the list method. This adjustment simplifies the query construction process, enhances readability, and maintains efficient data loading for related entities. Overall, these modifications streamline control flow and improve code structure.

Changes

File Path Change Summary
apiserver/plane/app/views/issue/relation.py Removed get_queryset method; simplified queryset construction in list method, focusing on workspace slug.

Poem

🐇 In the garden of code where issues bloom,
A refactor has come, dispelling the gloom.
With queries now clearer, the pathways align,
Simplicity reigns, and the logic will shine!
Hop, skip, and jump, let the changes take flight,
For a more graceful view, oh what a 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.

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 (4)
apiserver/plane/app/views/issue/relation.py (4)

38-38: Consider renaming the variable for clarity.

The variable issue_relations could be renamed to filtered_issue_relations to better reflect its purpose after filtering.

-        issue_relations = (
+        filtered_issue_relations = (

Line range hint 44-44:
Avoid redundant select_related calls.

The select_related calls for project, workspace, and issue can be combined into a single call to improve readability.

-            .select_related("project")
-            .select_related("workspace")
-            .select_related("issue")
+            .select_related("project", "workspace", "issue")

Line range hint 83-114:
Optimize annotations for better performance.

The annotations for link_count, attachment_count, and sub_issues_count can be optimized by combining them into a single annotate call.

-            .annotate(
-                link_count=IssueLink.objects.filter(issue=OuterRef("id"))
-                .order_by()
-                .annotate(count=Func(F("id"), function="Count"))
-                .values("count")
-            )
-            .annotate(
-                attachment_count=IssueAttachment.objects.filter(
-                    issue=OuterRef("id")
-                )
-                .order_by()
-                .annotate(count=Func(F("id"), function="Count"))
-                .values("count")
-            )
-            .annotate(
-                sub_issues_count=Issue.issue_objects.filter(
-                    parent=OuterRef("id")
-                )
-                .order_by()
-                .annotate(count=Func(F("id"), function="Count"))
-                .values("count")
-            )
+            .annotate(
+                link_count=IssueLink.objects.filter(issue=OuterRef("id"))
+                .order_by()
+                .annotate(count=Func(F("id"), function="Count"))
+                .values("count"),
+                attachment_count=IssueAttachment.objects.filter(
+                    issue=OuterRef("id")
+                )
+                .order_by()
+                .annotate(count=Func(F("id"), function="Count"))
+                .values("count"),
+                sub_issues_count=Issue.issue_objects.filter(
+                    parent=OuterRef("id")
+                )
+                .order_by()
+                .annotate(count=Func(F("id"), function="Count"))
+                .values("count")
+            )

Line range hint 147-147:
Ensure proper error handling.

The Project.objects.get(pk=project_id) call can raise a DoesNotExist exception. Consider adding error handling to manage this scenario.

-        project = Project.objects.get(pk=project_id)
+        try:
+            project = Project.objects.get(pk=project_id)
+        except Project.DoesNotExist:
+            return Response({"detail": "Project not found."}, status=status.HTTP_404_NOT_FOUND)
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2ee6cd2 and ef4cb45.

Files selected for processing (1)
  • apiserver/plane/app/views/issue/relation.py (2 hunks)

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 (2)
apiserver/plane/app/views/issue/relation.py (2)

Line range hint 124-124:
Consider handling potential exceptions in bulk_create.

Using bulk_create can raise exceptions if there are issues with the data. Consider adding error handling to manage such cases gracefully.

+        try:
+            issue_relation = IssueRelation.objects.bulk_create(
+                [
+                    IssueRelation(
+                        issue_id=(
+                            issue if relation_type == "blocking" else issue_id
+                        ),
+                        related_issue_id=(
+                            issue_id if relation_type == "blocking" else issue
+                        ),
+                        relation_type=(
+                            "blocked_by"
+                            if relation_type == "blocking"
+                            else relation_type
+                        ),
+                        project_id=project_id,
+                        workspace_id=project.workspace_id,
+                        created_by=request.user,
+                        updated_by=request.user,
+                    )
+                    for issue in issues
+                ],
+                batch_size=10,
+                ignore_conflicts=True,
+            )
+        except Exception as e:
+            return Response(
+                {"detail": str(e)},
+                status=status.HTTP_400_BAD_REQUEST,
+            )

Line range hint 170-170:
Consider handling potential exceptions in get and delete.

Using get and delete can raise exceptions if the objects are not found or if there are issues with the deletion. Consider adding error handling to manage such cases gracefully.

+        try:
+            if relation_type == "blocking":
+                issue_relation = IssueRelation.objects.get(
+                    workspace__slug=slug,
+                    project_id=project_id,
+                    issue_id=related_issue,
+                    related_issue_id=issue_id,
+                )
+            else:
+                issue_relation = IssueRelation.objects.get(
+                    workspace__slug=slug,
+                    project_id=project_id,
+                    issue_id=issue_id,
+                    related_issue_id=related_issue,
+                )
+        except IssueRelation.DoesNotExist:
+            return Response(
+                {"detail": "Issue relation not found."},
+                status=status.HTTP_404_NOT_FOUND,
+            )
+
+        current_instance = json.dumps(
+            IssueRelationSerializer(issue_relation).data,
+            cls=DjangoJSONEncoder,
+        )
+
+        try:
+            issue_relation.delete()
+        except Exception as e:
+            return Response(
+                {"detail": str(e)},
+                status=status.HTTP_400_BAD_REQUEST,
+            )
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ef4cb45 and ae68955.

Files selected for processing (1)
  • apiserver/plane/app/views/issue/relation.py (2 hunks)
Additional comments not posted (1)
apiserver/plane/app/views/issue/relation.py (1)

83-83: Ensure consistent usage of self.kwargs.get("slug").

The self.kwargs.get("slug") is used multiple times. Consider storing it in a variable for consistency and readability.

+        workspace_slug = self.kwargs.get("slug")
-            .filter(workspace__slug=self.kwargs.get("slug"))
+            .filter(workspace__slug=workspace_slug)

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants