@@ -91,27 +91,29 @@ def get(self, request: Request, organization: Organization) -> Response:
9191
9292 data : SupergroupsByGroupIdsResponse = orjson .loads (response .data )
9393
94+ if not status_param :
95+ return Response (data )
96+
9497 # Seer returns all group_ids per supergroup regardless of status.
9598 # We can't filter before the Seer call because Seer expands group_ids
9699 # to include the full supergroup membership, not just the requested IDs.
97100 # Instead, collect every group_id from the response, check status in
98101 # bulk, and strip out non-matching ones.
99- if status_param is not None :
100- all_response_group_ids : set [int ] = set ()
101- for sg in data ["data" ]:
102- all_response_group_ids .update (sg ["group_ids" ])
103-
104- matching_ids = set (
105- Group .objects .filter (
106- id__in = all_response_group_ids ,
107- project__organization = organization ,
108- status = STATUS_QUERY_CHOICES [status_param ],
109- ).values_list ("id" , flat = True )
110- )
102+ all_response_group_ids : set [int ] = set ()
103+ for sg in data ["data" ]:
104+ all_response_group_ids .update (sg ["group_ids" ])
105+
106+ matching_ids = set (
107+ Group .objects .filter (
108+ id__in = all_response_group_ids ,
109+ project__organization = organization ,
110+ status = STATUS_QUERY_CHOICES [status_param ],
111+ ).values_list ("id" , flat = True )
112+ )
111113
112- for sg in data ["data" ]:
113- sg ["group_ids" ] = [gid for gid in sg ["group_ids" ] if gid in matching_ids ]
114- # Drop supergroups that have no matching groups after filtering
115- data ["data" ] = [sg for sg in data ["data" ] if sg ["group_ids" ]]
114+ for sg in data ["data" ]:
115+ sg ["group_ids" ] = [gid for gid in sg ["group_ids" ] if gid in matching_ids ]
116+ # Drop supergroups that have no matching groups after filtering
117+ data ["data" ] = [sg for sg in data ["data" ] if sg ["group_ids" ]]
116118
117119 return Response (data )
0 commit comments