Skip to content

Commit

Permalink
fix: functionality for cached items
Browse files Browse the repository at this point in the history
  • Loading branch information
Skelmis committed Jan 4, 2024
1 parent 9a4b9ae commit 9a96cc9
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions garven/routers/aggregate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import logging
import os
from collections import defaultdict
from typing import TYPE_CHECKING

from fastapi import APIRouter, Depends
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9a96cc9

Please sign in to comment.