From f3ec2f36f8563d9a3f65c126a5bbb652e9fa45d5 Mon Sep 17 00:00:00 2001 From: kshitij <82637225+kshitijk4poor@users.noreply.github.com> Date: Fri, 7 Aug 2026 18:33:09 +0530 Subject: [PATCH] perf(slack): parallelize conversations.info lookups with asyncio.gather The dedup fix in #80679 reduced ~1.6k sequential API calls to ~30, but those ~30 calls were still sequential. Extract the per-base-ID resolution into an async helper and run all lookups concurrently via asyncio.gather. Turns a 6-15s serial block into <1s. --- gateway/channel_directory.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/gateway/channel_directory.py b/gateway/channel_directory.py index 1ffe6d6866..da643ba146 100644 --- a/gateway/channel_directory.py +++ b/gateway/channel_directory.py @@ -377,18 +377,20 @@ async def _build_slack(adapter) -> List[Dict[str, Any]]: seen_ids.add(eid) # Resolve remaining raw-ID entries (DMs, private channels not in bot scope) - # by calling conversations.info + users.info once per base conversation. + # by calling conversations.info + users.info once per base conversation, + # with all base-ID lookups running concurrently. unresolved = [ch for ch in channels if ch.get("name", "").startswith(("C0", "D0", "G0"))] if unresolved and team_clients: client = next(iter(team_clients.values())) unresolved_by_base = {} for entry in unresolved: unresolved_by_base.setdefault(slack_lookup_id(entry["id"]), []).append(entry) - for base_id, entries in unresolved_by_base.items(): + + async def _resolve_base(base_id: str, entries: list) -> None: try: resp = await client.conversations_info(channel=base_id) if not resp.get("ok"): - continue + return ch_info = resp.get("channel", {}) resolved_name = None resolved_type = None @@ -413,7 +415,10 @@ async def _build_slack(adapter) -> List[Dict[str, Any]]: entry["type"] = resolved_type except Exception as e: logger.debug("Channel directory: failed to resolve %s: %s", base_id, e) - continue + + await asyncio.gather( + *[_resolve_base(bid, ents) for bid, ents in unresolved_by_base.items()] + ) return channels