@@ -42,24 +42,26 @@ class GroupSimilarIssuesEmbeddingsEndpoint(GroupEndpoint):
42
42
"GET" : ApiPublishStatus .PRIVATE ,
43
43
}
44
44
45
- def get_group_hashes_for_group_id (self , group_id : int ) -> set [str ]:
46
- hashes = GroupHash .objects .filter (group_id = group_id )
47
- return {hash .hash for hash in hashes }
48
-
49
45
def get_formatted_results (
50
46
self ,
51
47
similar_issues_data : Sequence [SeerSimilarIssueData ],
52
48
user : User | AnonymousUser ,
53
- group_id : int ,
49
+ group : Group ,
54
50
) -> Sequence [tuple [Mapping [str , Any ], Mapping [str , Any ]] | None ]:
55
51
"""
56
52
Format the responses using to be used by the frontend by changing the field names and
57
53
changing the cosine distances into cosine similarities.
58
54
"""
59
- hashes = self .get_group_hashes_for_group_id (group_id )
60
55
group_data = {}
56
+ parent_hashes = [
57
+ similar_issue_data .parent_hash for similar_issue_data in similar_issues_data
58
+ ]
59
+ group_hashes = GroupHash .objects .filter (project_id = group .project_id , hash__in = parent_hashes )
60
+ parent_hashes_group_ids = {
61
+ group_hash .hash : group_hash .group_id for group_hash in group_hashes
62
+ }
61
63
for similar_issue_data in similar_issues_data :
62
- if similar_issue_data .parent_hash not in hashes :
64
+ if parent_hashes_group_ids [ similar_issue_data .parent_hash ] != group . id :
63
65
formatted_response : FormattedSimilarIssuesEmbeddingsData = {
64
66
"exception" : round (1 - similar_issue_data .stacktrace_distance , 4 ),
65
67
"shouldBeGrouped" : "Yes" if similar_issue_data .should_group else "No" ,
@@ -138,6 +140,6 @@ def get(self, request: Request, group: Group) -> Response:
138
140
139
141
if not results :
140
142
return Response ([])
141
- formatted_results = self .get_formatted_results (results , request .user , group . id )
143
+ formatted_results = self .get_formatted_results (results , request .user , group )
142
144
143
145
return Response (formatted_results )
0 commit comments