Tags: the tag list runs one COUNT query per tag #554
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#554
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, reading the tag list view and template and counting the page's queries in an experiment.Checked again on 2026-10-01 against
mainat0a5cad587: still present. The code is now atapplications/views.py:1085-1088(TagListView); the template line andIndustryListViewhave not moved.The Tags page prints how many applications carry each tag by calling the related manager's
count()in the template, and the view does not annotate that number. Every tag therefore costs its ownCOUNT(*)query. The industries list, which shows the same kind of column, already annotates it in one query.templates/applications/tag_list.html:31({{ tag.applications.count }});applications/views.py:1045-1048(TagListView, which inheritsget_querysetfromOwnedObjectMixinand adds nothing). Comparejobs/views.py:639(IndustryListView.get_queryset,annotate(company_count=Count("companies", distinct=True))).SELECT COUNT(*) ... applications_application_tagsper added tag. Measured with the snapshot's test settings and an in-memory database.tests/test_query_budget.pyexists to rule out (#231). That test does not catch it: itsfurnishalways reuses the same two tags, and the Tags page is not inPAGES.TagListViewaget_querysetthat returnssuper().get_queryset().annotate(application_count=Count("applications")), and print{{ tag.application_count }}in the template. One many-to-many join, sodistinct=Trueis not needed.Done when
tests/test_query_budget.pyopensapplications:tag_listwith 3 tags and again with 30 more, and asserts the two query counts are equal; it fails today (12 against 42) and passes after the fix.Landed on main with a green Forgejo CI run. Its entry in the CHANGELOG's Unreleased section ends in (#554).