You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I noticed today that Sentry was reporting a possible N+1 query issue on the dashboard homepage.
Here's the query that Sentry is claiming is being repeated:
SELECT dashboard_datum.id, dashboard_datum.content_type_id, dashboard_datum.object_id,
dashboard_datum.timestamp, dashboard_datum.measurement
FROM dashboard_datum
WHERE (
dashboard_datum.content_type_id = %s AND dashboard_datum.object_id = %s
)
ORDER BY dashboard_datum.timestamp DESC
LIMIT 1
I'd recomment trying to see ifthe Django Debug Toolbar (installed by default I think) is reporting the duplicated query also. And if so, we should try to fix it. Usually it's a matter of adding a select_related() or prefetch_related() somewhere in the view, but it might also be more complicated than that.
The text was updated successfully, but these errors were encountered:
Hi @bmispelon
As I observed, data is a reverse relationship (defined using GenericRelation in the Metric model), so I have updated the code to use prefetch_related("data") to optimize the query. Please review the changes in the PR.
Will you please let me know any changes need.
Thank you.
Mamatha1718
added a commit
to Mamatha1718/djangoproject.com
that referenced
this issue
Dec 30, 2024
I noticed today that Sentry was reporting a possible N+1 query issue on the dashboard homepage.
Here's the query that Sentry is claiming is being repeated:
I'd recomment trying to see ifthe Django Debug Toolbar (installed by default I think) is reporting the duplicated query also. And if so, we should try to fix it. Usually it's a matter of adding a
select_related()
orprefetch_related()
somewhere in the view, but it might also be more complicated than that.The text was updated successfully, but these errors were encountered: