cache-reform

This commit is contained in:
2024-03-12 15:50:57 +03:00
parent d1a510b093
commit 9b7aa57a18
5 changed files with 50 additions and 30 deletions

View File

@@ -204,7 +204,21 @@ async def get_authors_with_stat_cached(q):
records = []
with local_session() as session:
for x in session.execute(q):
stat_str = await redis.execute('GET', f'id:{x.id}:{'author'}')
stat_str = await redis.execute('GET', f'author:{x.id}')
if isinstance(stat_str, str):
x.stat = json.loads(stat_str).get('stat')
records.append(x)
except Exception as exc:
raise Exception(exc)
return records
async def get_topics_with_stat_cached(q):
try:
records = []
with local_session() as session:
for x in session.execute(q):
stat_str = await redis.execute('GET', f'topic:{x.id}')
if isinstance(stat_str, str):
x.stat = json.loads(stat_str).get('stat')
records.append(x)