aboutsummaryrefslogtreecommitdiffstats
path: root/slack
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2023-01-15 22:43:50 +0100
committerTrygve Aaberge <trygveaa@gmail.com>2024-02-18 11:32:53 +0100
commit65e245f20bfc67f4ada025543997a10c556c7fc2 (patch)
treebda0438488fc289a698fd8039e0d38beeb88bbcc /slack
parent0e9bbc4f4e0cf46a509609ce4de6d30360e17eb7 (diff)
downloadwee-slack-65e245f20bfc67f4ada025543997a10c556c7fc2.tar.gz
Don't fetch same users/bots multiple times
Diffstat (limited to 'slack')
-rw-r--r--slack/slack_workspace.py16
1 files changed, 10 insertions, 6 deletions
diff --git a/slack/slack_workspace.py b/slack/slack_workspace.py
index d4c932a..5074174 100644
--- a/slack/slack_workspace.py
+++ b/slack/slack_workspace.py
@@ -32,9 +32,11 @@ class SlackUsers(Dict[str, Future[SlackUser]]):
return self[key]
async def initialize_items(self, item_ids: Iterable[str]):
- items_info_task = create_task(self._fetch_items_info(item_ids))
- for item_id in set(item_ids):
- self[item_id] = create_task(self._create_item(item_id, items_info_task))
+ item_ids_to_init = set(item_id for item_id in item_ids if item_id not in self)
+ if item_ids_to_init:
+ items_info_task = create_task(self._fetch_items_info(item_ids_to_init))
+ for item_id in item_ids_to_init:
+ self[item_id] = create_task(self._create_item(item_id, items_info_task))
async def _create_item(
self,
@@ -68,9 +70,11 @@ class SlackBots(Dict[str, Future[SlackBot]]):
return self[key]
async def initialize_items(self, item_ids: Iterable[str]):
- items_info_task = create_task(self._fetch_items_info(item_ids))
- for item_id in set(item_ids):
- self[item_id] = create_task(self._create_item(item_id, items_info_task))
+ item_ids_to_init = set(item_id for item_id in item_ids if item_id not in self)
+ if item_ids_to_init:
+ items_info_task = create_task(self._fetch_items_info(item_ids_to_init))
+ for item_id in item_ids_to_init:
+ self[item_id] = create_task(self._create_item(item_id, items_info_task))
async def _create_item(
self,