[WEB-2020] chore: display cross project issue relations#5186
[WEB-2020] chore: display cross project issue relations#5186sriramveeraghanta merged 2 commits intopreviewfrom
Conversation
WalkthroughThe recent changes refactor the 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.
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_relationscould be renamed tofiltered_issue_relationsto better reflect its purpose after filtering.- issue_relations = ( + filtered_issue_relations = (
Line range hint
44-44:
Avoid redundantselect_relatedcalls.The
select_relatedcalls forproject,workspace, andissuecan 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, andsub_issues_countcan be optimized by combining them into a singleannotatecall.- .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 aDoesNotExistexception. 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)
There was a problem hiding this comment.
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 inbulk_create.Using
bulk_createcan 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 ingetanddelete.Using
getanddeletecan 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
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 ofself.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)
chore:
Issue Link: WEB-2020
Summary by CodeRabbit
Bug Fixes
Refactor
These changes should lead to a more intuitive experience when managing issue relations within the application.