Listings → Applied and Everything: one extra query per applied row, which the query budget test cannot see #558
Labels
No labels
accessibility
authentication
breaking change
bug
documentation
enhancement
interface
internationalisation
observability
performance
security
tier
1
tier
2
tier
3
tier/4
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
Postulo/postulo#558
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Found on 2026-09-29 in a read-only review of postulo at
95348908d, by counting the queries of each Listings tab as the data grows.Checked again on 2026-10-01 against
mainat0a5cad587: still present. The code is now atjobs/models.py:766-767(with_application_count) andjobs/models.py:821-835(undecidedandin_state); the template,ListingListView.get_querysetand the budget test have not moved.An applied row draws its Application button with
{% with application=listing.applications.all|first %}, andListingListView.get_querysetprefetches nothing, so each applied row on the page costs one more query, up to the page size. The query budget test added by #231 opens only the default tab, where no row is applied, so it cannot catch this.templates/jobs/partials/listing_row.html:115,jobs/listing_views.py:88-102ListingListView.get_queryset,jobs/models.py:763-764with_application_count(used byundecidedandin_state,jobs/models.py:818-832),tests/test_query_budget.py:93-101(PAGEShas("the listings page", "listings:list", {})only).Count("applications", distinct=True), aGROUP BYover every posting column, description included, which is the one-join aggregate #231 replaced withExistsand correlated subqueries elsewhere (tab_counts,CompanyQuerySet.with_table_data).first_application_id=Subquery(Application.objects.filter(posting=OuterRef("pk")).order_by("created_at", "pk").values("pk")[:1]), and link with{% url 'applications:detail' listing.first_application_id %}(orprefetch_related("applications")if the row needs more). Count applications withCoalesce(Subquery(...), 0)aswith_table_datadoes for companies. Add theappliedandalltabs toPAGES.Related to #231 (closed), whose budget test opens only the default tab.
Done when
tests/test_query_budget.pyhas("the listings page, applied", "listings:list", {"state": "applied"})and("the listings page, everything", "listings:list", {"state": "all"})inPAGES, with fixtures that include applied listings; both fail today.Landed on main with a green Forgejo CI run. Its entry in the CHANGELOG's Unreleased section ends in (#558).