Change Log list view has inefficient query #6885

Closed
opened 2025-12-29 19:46:19 +01:00 by adam · 2 comments
Owner

Originally created by @arthanson on GitHub (Aug 26, 2022).

Originally assigned to: @arthanson on GitHub.

Proposed Changes

need to add some select_related and prefetch_related to the Change Log list view to reduce the number of SQL queries.

Justification

On the demo site noticed the Change log list view was somewhat slow, checking in the debug toolbar with demo data saw it was generating over 100 SQL queries. For longer lists it will just get slower.

Originally created by @arthanson on GitHub (Aug 26, 2022). Originally assigned to: @arthanson on GitHub. ### Proposed Changes need to add some select_related and prefetch_related to the Change Log list view to reduce the number of SQL queries. ### Justification On the demo site noticed the Change log list view was somewhat slow, checking in the debug toolbar with demo data saw it was generating over 100 SQL queries. For longer lists it will just get slower.
adam added the status: acceptedtype: housekeeping labels 2025-12-29 19:46:19 +01:00
adam closed this issue 2025-12-29 19:46:19 +01:00
Author
Owner

@jeremystretch commented on GitHub (Aug 29, 2022):

need to add some select_related and prefetch_related to the Change Log list view

This is typically unnecessary as the dynamic table rendering takes care of attaching prefetches automatically depending on what columns have been selected for display. In this case, there's a bug with the full_name column where its template code is referencing record.user.get_full_name. We can fix this by setting the accessor for the column to the user field and tweaking the template code accordingly. The table will then pick up on the relation to the User model and attach the necessary prefetch to the queryset. This seems to be the case for changed_object as well.

@jeremystretch commented on GitHub (Aug 29, 2022): > need to add some select_related and prefetch_related to the Change Log list view This is typically unnecessary as the dynamic table rendering takes care of attaching prefetches automatically depending on what columns have been selected for display. In this case, there's a bug with the `full_name` column where its template code is referencing `record.user.get_full_name`. We can fix this by setting the accessor for the column to the `user` field and tweaking the template code accordingly. The table will then pick up on the relation to the User model and attach the necessary prefetch to the queryset. This seems to be the case for `changed_object` as well.
Author
Owner

@arthanson commented on GitHub (Aug 29, 2022):

@jeremystretch changed.

@arthanson commented on GitHub (Aug 29, 2022): @jeremystretch changed.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#6885