pycroft icon indicating copy to clipboard operation
pycroft copied to clipboard

N+1 Query in `user_show_logs_json`

Open agdsn-sentry[bot] opened this issue 1 year ago • 1 comments

Sentry Issue: PYCROFT-9C

Offending Spans db - SELECT "user".account_id AS user_account_i...

agdsn-sentry[bot] avatar Sep 18 '24 08:09 agdsn-sentry[bot]

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() the user.room
  • selectinload() the relevant logentries
  • joinedload() the logentries' author or something along these lines (measure!)

lukasjuhrich avatar Sep 18 '24 08:09 lukasjuhrich