api: prefetch roles on agenda display (#57670)

This commit is contained in:
Nicolas Roche 2021-10-08 10:12:30 +02:00
parent 5d1390223e
commit a7757b7a22
2 changed files with 4 additions and 4 deletions

View File

@ -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')
)

View File

@ -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):