WIP: model.get_leaderboard_sum_history and all appropriate stuff

This commit is contained in:
norohind committed 2021-12-10 00:56:48 +03:00
1 parent 8879f76372
commit 5360ab2e31
6 files changed
+128 -1

No files matched your search

+23
View File
@@ -143,3 +143,26 @@ class PostgresModel(AbstractModel):
cache.set(cache_key, json.dumps(result))
return result
@errors_catcher
def get_leaderboard_sum_history(self, platform: str, leaderboard_type: str) -> list[dict]:
cache_key = f'sum_history_{platform}_{leaderboard_type}'
cached_result: typing.Union[str, None] = cache.get(cache_key)
if cached_result is not None:
logger.debug(f'Cached result for {cache_key}')
return json.loads(cached_result)
with self.db.cursor(cursor_factory=psycopg2.extras.RealDictCursor) as cursor:
cursor.execute(
postgres_sql_requests.select_leaderboard_sum_history,
{
'LB_type': utils.LeaderboardTypes(leaderboard_type.lower()).value,
'platform': utils.Platform(platform.upper()).value}
)
result: list = cursor.fetchall()
if not cache.disabled:
cache.set(cache_key, json.dumps(result))
return result