Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions pgcommitfest/commitfest/ajax.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,19 @@ def getThreads(request):
else:
attachonly = 0

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

r = _archivesAPI("/list/pgsql-hackers/latest.json", params)
return sorted(r, key=lambda x: x["date"], reverse=True)
messages = {}
for listname in ("pgsql-hackers", "pgsql-bugs"):
for m in _archivesAPI("/list/%s/latest.json" % listname, params):
messages.setdefault(m["msgid"], m)

r = sorted(messages.values(), key=lambda x: x["date"], reverse=True)
return r[: params["n"]]


def getMessages(request):
Expand Down
38 changes: 38 additions & 0 deletions pgcommitfest/commitfest/tests/test_get_threads.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from django.test import RequestFactory

from unittest.mock import patch

from pgcommitfest.commitfest.ajax import getThreads


def _msg(msgid, date):
return {"msgid": msgid, "date": date, "from": "a@example.com", "subj": msgid}


def test_get_threads_searches_hackers_and_bugs():
hackers = [
_msg("h%d" % i, "2026-01-01T%02d:%02d:00" % (i // 60, i % 60))
for i in range(100)
]
# b1 is newer than everything on hackers, h99 was sent to both lists
bugs = [_msg("b1", "2026-01-02T00:00:00"), hackers[99]]

def fake(suburl, params=None):
return {
"/list/pgsql-hackers/latest.json": hackers,
"/list/pgsql-bugs/latest.json": bugs,
}[suburl]

request = RequestFactory().get("/ajax/getThreads/", {"s": "x", "a": "1"})
with patch("pgcommitfest.commitfest.ajax._archivesAPI", side_effect=fake) as api:
result = getThreads(request)

assert [c.args for c in api.call_args_list] == [
("/list/pgsql-hackers/latest.json", {"n": 100, "a": 1, "s": "x"}),
("/list/pgsql-bugs/latest.json", {"n": 100, "a": 1, "s": "x"}),
]
# Merged newest first, h99 deduplicated, and capped at 100 so the oldest
# message (h0) is dropped.
assert [m["msgid"] for m in result] == ["b1"] + [
"h%d" % i for i in range(99, 0, -1)
]
Loading