Skip to content

Commit 34ae32a

Browse files
committed
Append error and other results separately for sorting
1 parent 03540b9 commit 34ae32a

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

src/sentry/issues/escalating/escalating.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,17 +136,29 @@ def _query_groups_past_counts_eap(groups: Sequence[Group]) -> list[GroupsCountRe
136136
if not groups:
137137
return all_results
138138

139-
filtered_groups = [
140-
g
141-
for g in groups
142-
if g.issue_category == GroupCategory.ERROR or g.issue_type.should_detect_escalation()
143-
]
144-
if not filtered_groups:
139+
error_groups: list[Group] = []
140+
other_groups: list[Group] = []
141+
for g in groups:
142+
if g.issue_category == GroupCategory.ERROR:
143+
error_groups.append(g)
144+
elif g.issue_type.should_detect_escalation():
145+
other_groups.append(g)
146+
147+
all_results += _query_groups_eap_by_org(error_groups)
148+
all_results += _query_groups_eap_by_org(other_groups)
149+
150+
return all_results
151+
152+
153+
def _query_groups_eap_by_org(groups: Sequence[Group]) -> list[GroupsCountResponse]:
154+
"""Query EAP for groups, processing by organization."""
155+
all_results: list[GroupsCountResponse] = []
156+
if not groups:
145157
return all_results
146158

147159
start_date, end_date = _start_and_end_dates()
148160

149-
groups_by_org = _extract_organization_and_project_and_group_ids(filtered_groups)
161+
groups_by_org = _extract_organization_and_project_and_group_ids(groups)
150162

151163
for organization_id in sorted(groups_by_org.keys()):
152164
group_ids_by_project = groups_by_org[organization_id]
@@ -213,7 +225,7 @@ def _query_groups_past_counts_eap(groups: Sequence[Group]) -> list[GroupsCountRe
213225
)
214226
continue
215227

216-
# Sort to match Snuba ordering (project_id, group_id, hourBucket)
228+
# Sort to match Snuba's orderby: (project_id, group_id, hourBucket)
217229
all_results.sort(key=lambda x: (x["project_id"], x["group_id"], x["hourBucket"]))
218230

219231
return all_results

0 commit comments

Comments
 (0)