From 9a96cc97fc5755bfa969256dd154cf9d12aaac8e Mon Sep 17 00:00:00 2001 From: skelmis Date: Thu, 4 Jan 2024 16:17:35 +1300 Subject: [PATCH] fix: functionality for cached items --- garven/routers/aggregate.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/garven/routers/aggregate.py b/garven/routers/aggregate.py index cef1c40..5fae810 100644 --- a/garven/routers/aggregate.py +++ b/garven/routers/aggregate.py @@ -2,6 +2,7 @@ import logging import os +from collections import defaultdict from typing import TYPE_CHECKING from fastapi import APIRouter, Depends @@ -55,16 +56,20 @@ async def guild_count(request: Request): async def cached_item_counter(request: Request): z: Server = request.app.zonis partial_response = False - data: dict[str, dict[str, int]] = await z.request_all("cached_item_count") - totals: dict[str, int] = {k: 0 for k in data.keys()} + raw_data: dict[str, dict[str, int]] = await z.request_all("cached_item_count") + totals: dict[str, int] = defaultdict(lambda: 0) + data: dict[str, dict[str, int]] = {} - for key, value in data.items(): - if isinstance(value, RequestFailed): + for cluster, item in raw_data.items(): + if isinstance(item, RequestFailed): partial_response = True - log.error("/cached/count WS threw '%s'", value.response_data) + log.error("/cached/count WS threw '%s'", item.response_data) continue - totals[key] += value + data[cluster] = item + + for key, value in item.items(): + totals[key] += value statistic = CachedItemsStatistic( per_cluster=data, partial_response=partial_response, total_counts=totals