Skip to content

Commit

Permalink
fix(metrics-extraction): Fix n+1 due to filter (#64902)
Browse files Browse the repository at this point in the history
### Summary
Filter apparently ignores the prefetched `...ondemand_set` so we need to
do this in memory, unfortunately, otherwise have hundreds of short
queries being run.

---------

Co-authored-by: getsantry[bot] <66042841+getsantry[bot]@users.noreply.github.com>
  • Loading branch information
k-fish and getsantry[bot] authored Feb 9, 2024
1 parent 5e26ab0 commit 70898e1
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/sentry/relay/config/metric_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,9 +467,11 @@ def _can_widget_query_use_stateful_extraction(
default_version_specs = specs_per_version.get(stateful_extraction_version, [])
spec_hashes = [hashed_spec[0] for hashed_spec in default_version_specs]

on_demand_entries = widget_query.dashboardwidgetqueryondemand_set.filter(
spec_version=stateful_extraction_version
)
on_demand_entries = [
entry
for entry in widget_query.dashboardwidgetqueryondemand_set.all()
if entry.spec_version == stateful_extraction_version
]

if len(on_demand_entries) == 0:
# 0 on-demand entries is expected, and happens when the on-demand task hasn't caught up yet for newly created widgets or widgets recently modified to have on-demand state.
Expand Down

0 comments on commit 70898e1

Please sign in to comment.