Skip to content

Commit baba700

Browse files
authored
Filter fetched existing issues by revision and diff (#2517)
* Filter fetched existing issues by revision and diff * Add iterator * Preserve issues with no link * Update tests
1 parent 6695f42 commit baba700

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

backend/code_review_backend/issues/serializers.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,20 @@ def create(self, validated_data):
274274
ignore_conflicts=True,
275275
)
276276
# List issues again to ensure ID are synced for creating links
277-
issues_with_links = (
277+
issues_with_links = list(
278278
Issue.objects.values("issue_links")
279-
.filter(hash__in=[issue.hash for issue in issues])
279+
.filter(
280+
Q(
281+
# Issue is new for this diff/revision
282+
issue_links__isnull=True,
283+
)
284+
| Q(
285+
# Issue exists for this diff/revision
286+
issue_links__diff=diff,
287+
issue_links__revision=self.context["revision"],
288+
),
289+
hash__in=[issue.hash for issue in issues],
290+
)
280291
# Needed for re-serialization
281292
.annotate(publishable=Q(issue_links__in_patch=True) & Q(level=LEVEL_ERROR))
282293
.values(
@@ -294,6 +305,7 @@ def create(self, validated_data):
294305
"issue_links__nb_lines",
295306
"issue_links__char",
296307
)
308+
.iterator()
297309
)
298310
# Group existing links by issue
299311
grouped_issues = [

backend/code_review_backend/issues/tests/test_api.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,6 @@ def test_create_issue_bulk_alread_exists(self):
419419
)
420420

421421
# Calling again with the same payload should give the same result
422-
# 1 less request is fired to the DB because no IssueLink is created
423422
with self.assertNumQueries(5):
424423
response = self.client.post(
425424
f"/v1/revision/{self.revision.id}/issues/", payload_2, format="json"

0 commit comments

Comments
 (0)