Skip to content

perf: optimize the person endpoint - #11635

Merged
jennifer-richards merged 9 commits into
mainfrom
optimize_person
Aug 27, 2026
Merged

perf: optimize the person endpoint#11635
jennifer-richards merged 9 commits into
mainfrom
optimize_person

Conversation

@rjsparks

Copy link
Copy Markdown
Member

No description provided.

rjsparks and others added 7 commits August 24, 2026 19:59
Keyed on the Cloudflare client address, with an empty key for every other
path so only these two prefixes are limited.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Gathers the RFC publication dates, reference counts and replaced-draft set for
every listed person in one query each, rather than a query per table cell, and
evaluates each per-person list once instead of on every template reference.

The expired Internet-Drafts heading now counts the drafts it lists; it counted
the replaced ones the list omits. Roles with the same name sort by group
acronym instead of by whatever order the query returned.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
A repeat view of a profile, including the revalidation behind a conditional
request, now costs neither the queries nor the render. Sections are keyed on
person and date rather than position on the page, so the per-section element
ids move from a loop counter to the person's id.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

@jennifer-richards jennifer-richards left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems generally fine. Minor comment, a nit, and a more substantive change suggested for the cache keying / statement about "today" - see inline.

Comment thread ietf/person/utils.py
# Email.address is a citext column, so an exact match is already
# case-insensitive and can use the index on it. Asking for iexact wraps the
# column in UPPER() and costs a scan of the table.
emails = Email.objects.filter(address=email_or_name).select_related("person")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This obligates us to use a case-insensitive collation for this field when we move to Django 5.2. I think we want to do that anyway, but we need to remember to adjust this if we take a different approach with collation.

Comment thread ietf/person/views.py Outdated

REFERENCE_RELATIONSHIPS = ("refnorm", "refinfo", "refunk", "refold")

PROFILE_CACHE_SECONDS = 900

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps expose via settings?

Comment thread ietf/person/views.py Outdated
"""
slowpages = caches["slowpages"]
keys = {
person.pk: f"person:profile:{person.pk}:{timezone.localdate(today)}"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think keying on the date makes sense - it's redundant with the cache timeout knob, except in not meaningful corners. In particular, it doesn't keep all the sections of the profile page in sync with each other unless you assume particular timing of role changes relative to midnight.

I guess it's here to keep the sections all agreeing on "has no roles as of " in the display. IMO either let that vary, or (even better) change it to "does not currently have any roles" and be vague about exactly what instant that refers to. Strictly speaking that's more accurate than the existing behavior.

Comment thread ietf/templates/person/profile_body.html Outdated
</tbody>
</table>
{% else %}
<p>{{ person.first_name }} has no active roles as of {{ today|date:"Y-m-d" }}.</p>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment above about perhaps changing the "as of " text + interpolation

rjsparks and others added 2 commits August 27, 2026 14:44
PERSON_PROFILE_CACHE_SECONDS, overridable from the environment in the k8s
deployment.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The dates claimed a precision the page does not have: sections are cached
independently, so the data behind two of them can differ by a cache lifetime
while both printed the same date. Without them nothing in a section depends on
when it was rendered, so the cache key no longer needs the date either.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@jennifer-richards
jennifer-richards marked this pull request as ready for review August 27, 2026 20:28
@jennifer-richards
jennifer-richards merged commit ba394a1 into main Aug 27, 2026
7 checks passed
@jennifer-richards
jennifer-richards deleted the optimize_person branch August 27, 2026 20:28
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Aug 31, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

2 participants