Skip to content

Commit 1b04625

Browse files
Search pgsql-bugs too when attaching a thread (#121)
Fixes #117 The "Attach thread" search only looked at pgsql-hackers, so a patch for a bug report could only be attached by pasting its message id. Now it searches pgsql-bugs too, and merges the results newest first. --------- Co-authored-by: Jelterminator FennemAI-Neo <fennemai@jeltef.nl>
1 parent fbd344d commit 1b04625

2 files changed

Lines changed: 47 additions & 3 deletions

File tree

‎pgcommitfest/commitfest/ajax.py‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,19 @@ def getThreads(request):
8787
else:
8888
attachonly = 0
8989

90-
# Make a JSON api call to the archives server
90+
# Make a JSON api call to the archives server for each list. A message
91+
# that was sent to more than one list is only returned once.
9192
params = {"n": 100, "a": attachonly}
9293
if search:
9394
params["s"] = search
9495

95-
r = _archivesAPI("/list/pgsql-hackers/latest.json", params)
96-
return sorted(r, key=lambda x: x["date"], reverse=True)
96+
messages = {}
97+
for listname in ("pgsql-hackers", "pgsql-bugs"):
98+
for m in _archivesAPI("/list/%s/latest.json" % listname, params):
99+
messages.setdefault(m["msgid"], m)
100+
101+
r = sorted(messages.values(), key=lambda x: x["date"], reverse=True)
102+
return r[: params["n"]]
97103

98104

99105
def getMessages(request):
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from django.test import RequestFactory
2+
3+
from unittest.mock import patch
4+
5+
from pgcommitfest.commitfest.ajax import getThreads
6+
7+
8+
def _msg(msgid, date):
9+
return {"msgid": msgid, "date": date, "from": "a@example.com", "subj": msgid}
10+
11+
12+
def test_get_threads_searches_hackers_and_bugs():
13+
hackers = [
14+
_msg("h%d" % i, "2026-01-01T%02d:%02d:00" % (i // 60, i % 60))
15+
for i in range(100)
16+
]
17+
# b1 is newer than everything on hackers, h99 was sent to both lists
18+
bugs = [_msg("b1", "2026-01-02T00:00:00"), hackers[99]]
19+
20+
def fake(suburl, params=None):
21+
return {
22+
"/list/pgsql-hackers/latest.json": hackers,
23+
"/list/pgsql-bugs/latest.json": bugs,
24+
}[suburl]
25+
26+
request = RequestFactory().get("/ajax/getThreads/", {"s": "x", "a": "1"})
27+
with patch("pgcommitfest.commitfest.ajax._archivesAPI", side_effect=fake) as api:
28+
result = getThreads(request)
29+
30+
assert [c.args for c in api.call_args_list] == [
31+
("/list/pgsql-hackers/latest.json", {"n": 100, "a": 1, "s": "x"}),
32+
("/list/pgsql-bugs/latest.json", {"n": 100, "a": 1, "s": "x"}),
33+
]
34+
# Merged newest first, h99 deduplicated, and capped at 100 so the oldest
35+
# message (h0) is dropped.
36+
assert [m["msgid"] for m in result] == ["b1"] + [
37+
"h%d" % i for i in range(99, 0, -1)
38+
]

0 commit comments

Comments
 (0)