eschutho commented on code in PR #35832:
URL: https://github.com/apache/superset/pull/35832#discussion_r2482782001


##########
superset/utils/slack.py:
##########
@@ -117,22 +116,151 @@ def get_channels() -> list[SlackChannelSchema]:
         raise
 
 
+def _fetch_channels_without_search(
+    client: WebClient,
+    channel_schema: SlackChannelSchema,
+    types_param: str,
+    cursor: Optional[str],
+    limit: int,
+) -> dict[str, Any]:
+    """Fetch channels without search filtering, paginating for large limits."""
+    channels: list[SlackChannelSchema] = []
+    slack_cursor = cursor
+    page_size = min(limit, 200)
+
+    while True:
+        response = client.conversations_list(
+            limit=page_size,
+            cursor=slack_cursor,
+            exclude_archived=True,
+            types=types_param,
+        )
+
+        page_channels = [
+            channel_schema.load(channel) for channel in 
response.data["channels"]
+        ]
+        channels.extend(page_channels)
+
+        slack_cursor = response.data.get("response_metadata", 
{}).get("next_cursor")
+
+        if not slack_cursor or len(page_channels) < page_size or len(channels) 
>= limit:
+            break
+
+    return {
+        "result": channels[:limit],
+        "next_cursor": slack_cursor,
+        "has_more": bool(slack_cursor),
+    }
+
+
+def _fetch_channels_with_search(
+    client: WebClient,
+    channel_schema: SlackChannelSchema,
+    types_param: str,
+    search_string: str,
+    exact_match: bool,
+    cursor: Optional[str],
+    limit: int,
+) -> dict[str, Any]:
+    """Fetch channels with search filtering, streaming through pages."""
+    matches: list[SlackChannelSchema] = []
+    slack_cursor = cursor
+    max_pages_to_fetch = 50
+    pages_fetched = 0
+    search_string_lower = search_string.lower()
+
+    while len(matches) < limit and pages_fetched < max_pages_to_fetch:
+        response = client.conversations_list(
+            limit=200,
+            cursor=slack_cursor,
+            exclude_archived=True,
+            types=types_param,
+        )
+
+        for channel_data in response.data["channels"]:
+            channel_name_lower = channel_data["name"].lower()
+            channel_id_lower = channel_data["id"].lower()
+
+            is_match = False
+            if exact_match:
+                is_match = (
+                    search_string_lower == channel_name_lower
+                    or search_string_lower == channel_id_lower
+                )
+            else:
+                is_match = (
+                    search_string_lower in channel_name_lower
+                    or search_string_lower in channel_id_lower

Review Comment:
   One thing to note here is that the search string can be a comma separated 
list, and we need to split it and search each string separately. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to