From a7757b7a2274afff5678180b70cddbcb5a43a957 Mon Sep 17 00:00:00 2001 From: Nicolas ROCHE Date: Fri, 8 Oct 2021 10:12:30 +0200 Subject: [PATCH] api: prefetch roles on agenda display (#57670) --- chrono/api/views.py | 2 +- tests/api/test_all.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/chrono/api/views.py b/chrono/api/views.py index 351640cc..5f6e4da8 100644 --- a/chrono/api/views.py +++ b/chrono/api/views.py @@ -706,7 +706,7 @@ class Agendas(APIView): def get(self, request, format=None): agendas_queryset = ( Agenda.objects.all() - .select_related('absence_reasons_group', 'category') + .select_related('absence_reasons_group', 'category', 'edit_role', 'view_role') .prefetch_related('resources', 'absence_reasons_group__absence_reasons') .order_by('label') ) diff --git a/tests/api/test_all.py b/tests/api/test_all.py index 5ac8a075..ef24a2ae 100644 --- a/tests/api/test_all.py +++ b/tests/api/test_all.py @@ -181,10 +181,10 @@ def test_agendas_api(app): with CaptureQueriesContext(connection) as ctx: resp = app.get('/api/agenda/') - assert len(ctx.captured_queries) == 8 + assert len(ctx.captured_queries) == 4 with CaptureQueriesContext(connection) as ctx: resp = app.get('/api/agenda/', params={'q': 'MEET'}) - assert len(ctx.captured_queries) == 3 + assert len(ctx.captured_queries) == 2 resp = app.get('/api/agenda/', params={'with_open_events': '1'}) assert len(resp.json['data']) == 0 @@ -291,7 +291,7 @@ def test_agendas_api(app): with CaptureQueriesContext(connection) as ctx: resp = app.get('/api/agenda/', params={'with_open_events': '1'}) - assert len(ctx.captured_queries) == 9 + assert len(ctx.captured_queries) == 8 def test_agendas_meetingtypes_api(app, some_data, meetings_agenda):