From 2230242b9b7c6f3c64a0e32d96ce6ac004dffe54 Mon Sep 17 00:00:00 2001 From: Jennifer Richards Date: Thu, 22 Aug 2024 12:34:52 -0300 Subject: [PATCH] refactor: speed up finalizing proceedings (#7846) * chore: increase nginx proxy_read_timeout * refactor: speed up bluesheet_data The affiliation helper was extremely slow. Using queryset annotation speeds it up by almost an order of magnitude. * chore: delint --- ietf/meeting/utils.py | 31 ++++++++++++++++++++----------- k8s/nginx-auth.conf | 4 ++++ k8s/nginx-datatracker.conf | 4 ++++ 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/ietf/meeting/utils.py b/ietf/meeting/utils.py index e3d8c830ee..b68a311f5d 100644 --- a/ietf/meeting/utils.py +++ b/ietf/meeting/utils.py @@ -12,7 +12,8 @@ from django.conf import settings from django.contrib import messages -from django.db.models import Q +from django.db.models import OuterRef, Subquery, TextField, Q, Value +from django.db.models.functions import Coalesce from django.template.loader import render_to_string from django.utils import timezone from django.utils.encoding import smart_str @@ -149,19 +150,27 @@ def create_proceedings_templates(meeting): def bluesheet_data(session): - def affiliation(meeting, person): - # from OidcExtraScopeClaims.scope_registration() - email_list = person.email_set.values_list("address") - q = Q(person=person, meeting=meeting) | Q(email__in=email_list, meeting=meeting) - reg = MeetingRegistration.objects.filter(q).exclude(affiliation="").first() - return reg.affiliation if reg else "" - - attendance = Attended.objects.filter(session=session).order_by("time") - meeting = session.meeting + attendance = ( + Attended.objects.filter(session=session) + .annotate( + affiliation=Coalesce( + Subquery( + MeetingRegistration.objects.filter( + Q(meeting=session.meeting), + Q(person=OuterRef("person")) | Q(email=OuterRef("person__email")), + ).values("affiliation")[:1] + ), + Value(""), + output_field=TextField(), + ) + ).distinct() + .order_by("time") + ) + return [ { "name": attended.person.plain_name(), - "affiliation": affiliation(meeting, attended.person), + "affiliation": attended.affiliation, } for attended in attendance ] diff --git a/k8s/nginx-auth.conf b/k8s/nginx-auth.conf index 6dd5d6ed56..a38b8f50c7 100644 --- a/k8s/nginx-auth.conf +++ b/k8s/nginx-auth.conf @@ -34,5 +34,9 @@ server { proxy_set_header X-Forwarded-For $${keepempty}proxy_add_x_forwarded_for; proxy_set_header X-Real-IP $${keepempty}remote_addr; proxy_pass http://localhost:8000; + # Set timeouts longer than Cloudflare proxy limits + proxy_connect_timeout 60; # nginx default (Cf = 15) + proxy_read_timeout 120; # nginx default = 60 (Cf = 100) + proxy_send_timeout 60; # nginx default = 60 (Cf = 30) } } diff --git a/k8s/nginx-datatracker.conf b/k8s/nginx-datatracker.conf index 5cbc22e6c7..7c0dc85fd0 100644 --- a/k8s/nginx-datatracker.conf +++ b/k8s/nginx-datatracker.conf @@ -23,6 +23,10 @@ server { proxy_set_header X-Forwarded-For $${keepempty}proxy_add_x_forwarded_for; proxy_set_header X-Real-IP $${keepempty}remote_addr; proxy_pass http://localhost:8000; + # Set timeouts longer than Cloudflare proxy limits + proxy_connect_timeout 60; # nginx default (Cf = 15) + proxy_read_timeout 120; # nginx default = 60 (Cf = 100) + proxy_send_timeout 60; # nginx default = 60 (Cf = 30) client_max_body_size 0; # disable size check } }