Skip to content

Commit 8f5876f

Browse files
committed
Always include threads in the per-commitfest patches endpoint
GET /api/v1/commitfests/<cfid>/patches now returns each patch's threads unconditionally, so the ?include=threads parameter is removed. Unknown query parameters are ignored, so existing callers passing it keep working.
1 parent 95965b7 commit 8f5876f

2 files changed

Lines changed: 17 additions & 42 deletions

File tree

‎pgcommitfest/commitfest/apiv1.py‎

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,34 +66,28 @@ def commitfest_patches(request, cfid):
6666
This endpoint provides the data that cfbot previously scraped from the
6767
commitfest HTML page.
6868
69-
Threads for every patch can be included with ?include=threads. Unknown
70-
tokens are ignored.
69+
Each patch includes its threads, in the same shape as
70+
/patches/<id>/threads.
7171
"""
7272
cf = get_object_or_404(CommitFest, pk=cfid)
7373

74-
include = {i.strip() for i in request.GET.get("include", "").split(",")}
75-
include_threads = "threads" in include
76-
7774
pocs = (
7875
PatchOnCommitFest.objects.filter(commitfest=cf)
7976
.select_related("patch")
80-
.prefetch_related("patch__authors")
81-
.order_by("patch__id")
82-
)
83-
84-
if include_threads:
85-
pocs = pocs.prefetch_related(
77+
.prefetch_related(
78+
"patch__authors",
8679
Prefetch(
8780
"patch__mailthread_set",
8881
queryset=MailThread.objects.with_has_attachment(),
89-
)
82+
),
9083
)
84+
.order_by("patch__id")
85+
)
9186

9287
patches = []
9388
for poc in pocs:
9489
entry = poc.to_json()
95-
if include_threads:
96-
entry["threads"] = poc.patch.mailthread_set.all()
90+
entry["threads"] = poc.patch.mailthread_set.all()
9791
patches.append(entry)
9892

9993
return api_response(

‎pgcommitfest/commitfest/tests/test_apiv1.py‎

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def test_commitfest_patches_endpoint(client, open_cf, alice, bob):
174174
)
175175

176176
url = f"/api/v1/commitfests/{open_cf.id}/patches"
177-
with CaptureQueriesContext(connection) as queries_without_threads:
177+
with CaptureQueriesContext(connection) as queries:
178178
response = client.get(url)
179179

180180
assert response.status_code == 200
@@ -205,14 +205,6 @@ def test_commitfest_patches_endpoint(client, open_cf, alice, bob):
205205
assert p2["enterdate"] == "2025-01-02T08:00:00+00:00"
206206
assert p2["leavedate"] == "2025-01-20T16:45:00+00:00"
207207

208-
# Threads are opt-in
209-
assert "threads" not in p1
210-
211-
with CaptureQueriesContext(connection) as queries_with_threads:
212-
response = client.get(f"{url}?include=threads")
213-
214-
assert response.status_code == 200
215-
p1, p2 = json.loads(response.content)["patches"]
216208
assert p1["threads"] == [
217209
{
218210
"messageid": "abc123@example.com",
@@ -223,25 +215,14 @@ def test_commitfest_patches_endpoint(client, open_cf, alice, bob):
223215
}
224216
]
225217
assert p2["threads"] == []
226-
# A single prefetch query for all patches, not one per patch
227-
assert len(queries_with_threads) == len(queries_without_threads) + 1
228-
229-
230-
def test_commitfest_patches_endpoint_include_parsing(client, open_cf):
231-
"""Unknown include tokens are ignored and spaces around tokens allowed."""
232-
PatchOnCommitFest.objects.create(
233-
patch=Patch.objects.create(name="Add feature X"),
234-
commitfest=open_cf,
235-
enterdate=datetime(2025, 1, 1, 12, 0, 0, tzinfo=timezone.utc),
236-
)
237-
url = f"/api/v1/commitfests/{open_cf.id}/patches"
238-
239-
response = client.get(f"{url}?include=bogus")
240-
assert response.status_code == 200
241-
assert "threads" not in json.loads(response.content)["patches"][0]
242-
243-
response = client.get(f"{url}?include=bogus, threads")
244-
assert json.loads(response.content)["patches"][0]["threads"] == []
218+
# Threads (with has_attachment) are fetched in a single prefetch query for
219+
# all patches, not one per patch
220+
thread_queries = [
221+
q
222+
for q in queries.captured_queries
223+
if "commitfest_mailthreadattachment" in q["sql"]
224+
]
225+
assert len(thread_queries) == 1
245226

246227

247228
def test_commitfest_patches_endpoint_not_found(client, commitfests):

0 commit comments

Comments
 (0)