Skip to content

Commit

Permalink
Fix retrieve_config, so it actually retrieves all entries if not key …
Browse files Browse the repository at this point in the history
…is provided
  • Loading branch information
dwrss committed Jun 9, 2024
1 parent 37fba6d commit ec8145c
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions botto/storage/config_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async def list_config_by_server(self) -> ConfigCache:

async def retrieve_config(
self, server_id: str | int, key: Optional[Union[str, int]]
) -> Optional[ConfigEntry]:
) -> Optional[ConfigEntry | dict[str, ConfigEntry]]:
log.debug(f"Fetching {key or 'config'} for {server_id}")
filter_by_formula = f"AND({{Server ID}}='{server_id}'"
if key := key:
Expand All @@ -56,13 +56,13 @@ async def retrieve_config(
)
config_iterator = (ConfigEntry.from_airtable(x) async for x in result_iterator)
try:
config = await config_iterator.__anext__()
async with self.config_lock:
server_config = self.config_cache.get(str(server_id), {})
server_config[config.config_key] = config
self.config_cache[config.server_id] = server_config
return config
except (StopIteration, StopAsyncIteration):
async for config in config_iterator:
server_config[config.config_key] = config
self.config_cache[str(server_id)] = server_config
return server_config if not key else server_config[key]
except (StopIteration, StopAsyncIteration, KeyError):
log.info(f"No config found for Key {key} with Server ID {server_id}")
return None

Expand Down

0 comments on commit ec8145c

Please sign in to comment.