pycroft
pycroft copied to clipboard
N+1 Query in `user_show_logs_json`
These 6 lazy fetches cause ~300ms in the linked event. This is not negligible!
https://github.com/agdsn/pycroft/blob/968f2adde70f108cc88c3b9f5dc5b7c62f541ba2/web/blueprints/user/init.py#L407-L420 https://github.com/agdsn/pycroft/blob/968f2adde70f108cc88c3b9f5dc5b7c62f541ba2/web/blueprints/user/init.py#L394-L402 https://github.com/agdsn/pycroft/blob/968f2adde70f108cc88c3b9f5dc5b7c62f541ba2/web/blueprints/helpers/log.py#L28-L42
It seems to me that these fetches come from entry.author, where entry is in user.log_entries, user.room.log_entries, user.task_log_entries.
We should try to
-
joinedload()theuser.room -
selectinload()the relevant logentries -
joinedload()the logentries' author or something along these lines (measure!)