Skip to content

Commit

Permalink
Refactor _metrics_queries_plan_from_request to use IN conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
sentry-autofix[bot] authored Apr 2, 2024
1 parent dc111b1 commit 69a0de3
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/sentry/api/endpoints/organization_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,17 @@ def _metrics_queries_plan_from_request(self, request: Request) -> MetricsQueries
metrics_queries_plan = MetricsQueriesPlan()

queries = request.data.get("queries") or []
for query in queries:
metrics_queries_plan.declare_query(name=query["name"], mql=query["mql"])
# Placeholder for refactored logic to use IN conditions
# Group queries by a common attribute if applicable
grouped_queries = group_queries_by_attribute(queries)
for group in grouped_queries:
if len(group) > 1:
# Use IN condition for groups with more than one query
in_condition = construct_in_condition(group)
metrics_queries_plan.declare_query(name=group[0]["name"], mql=in_condition)
else:
# Single query, no change needed
metrics_queries_plan.declare_query(name=group[0]["name"], mql=group[0]["mql"])

formulas = request.data.get("formulas") or []
for formula in formulas:
Expand Down

0 comments on commit 69a0de3

Please sign in to comment.