Skip to content

Add opt-in threads and enterdate/leavedate to the per-commitfest patches endpoint - #115

Merged
JelteF merged 13 commits into
postgres:mainfrom
kjrocker:api-patches-include-threads
Oct 18, 2026
Merged

JelteF merged 13 commits into
postgres:mainfrom
kjrocker:api-patches-include-threads

Conversation

@kjrocker

@kjrocker kjrocker commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Getting the threads for all patches in a commitfest required one GET /api/v1/patches/<id>/threads request per patch, which makes fetching the history thousands of requests. With ?include=threads, GET /api/v1/commitfests/<cfid>/patches now includes a threads list for every patch, in the same shape as the per-patch endpoint, at the cost of a single extra query.

The endpoint now also always returns enterdate and leavedate. Like draft from #114, these were already stored and shown in the UI, just not exposed in the API.

Threads for a whole commitfest in one prefetch query instead of a
request per patch. enterdate/leavedate were already stored, just not
exposed.
@kjrocker
kjrocker marked this pull request as draft September 2, 2026 14:25
Helpers above the tests, create_thread called with keyword arguments,
comments trimmed to the terser house style.
@kjrocker
kjrocker force-pushed the api-patches-include-threads branch from 5b184fa to 874c6a5 Compare September 2, 2026 14:44
@kjrocker
kjrocker marked this pull request as ready for review September 2, 2026 14:48
FennemAI and others added 11 commits October 18, 2026 09:59
The four separate tests for `?include=threads` each rebuilt the same
patch/thread fixtures to check one property. They now share the setup of
`test_commitfest_patches_endpoint`, which already has two patches on a
commitfest: one gets a thread with an attachment, so the same test checks
that threads are opt-in, that unknown include tokens are ignored, the
inlined thread payload, the empty list for a patch without threads, and
that including threads costs a single extra query rather than one per
patch.

The remaining naive `datetime.now()` in the file is replaced with a fixed
aware datetime so the pre-commit ruff check passes.
`?include=bogus, threads` used to silently return no threads, because the
token was compared as " threads". Strip whitespace from each token so a
space after the comma works as people would expect.
This matches how `CommitFest` already provides its own API representation
through `to_json`.
The per-commitfest patches endpoint built each patch entry inline. Like
`CommitFest` and `MailThread`, the models now provide their own API
representation: `Patch.to_json` has the patch fields, and
`PatchOnCommitFest.to_json` adds the commitfest-specific status and
enter/leave dates on top.
`MailThread.to_json` depends on the `has_attachment` annotation, so the
helper that adds it belongs next to the model rather than in the API
module. Now it's available as `MailThread.objects.with_has_attachment()`
and on related managers like `patch.mailthread_set.with_has_attachment()`.
`to_json` raised an `AttributeError` for threads that weren't fetched
through `with_has_attachment()`. Now `has_attachment` is a property that
uses the annotation when it's there and otherwise checks the attachments
with a query, so the annotation is only a performance optimization.
Keeps the main patches endpoint test focused on the response contents,
and makes it clear what the include parsing is expected to do.
`api_response` already calls `to_json` on objects that have it, so there's
no need to do that explicitly for the threads.
The JSON serializer now turns querysets into lists itself, so views can
put a queryset in the response without wrapping it in `list()`.
@JelteF
JelteF merged commit c5a387a into postgres:main Oct 18, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants