From 0ca83cc91e4a4135893a24e6cb31bbab07356b2d Mon Sep 17 00:00:00 2001 From: Untone Date: Sat, 24 Feb 2024 09:26:31 +0300 Subject: [PATCH] cache authors by id --- services/follows.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/services/follows.py b/services/follows.py index d6d7507e..a89b6431 100644 --- a/services/follows.py +++ b/services/follows.py @@ -12,13 +12,16 @@ from services.rediscache import redis DEFAULT_FOLLOWS = { 'topics': [], 'authors': [], - 'communities': [{'slug': 'discours', 'name': 'Дискурс', 'id': 1, 'desc': ''}], + 'communities': [{'slug': 'discours', 'name': 'Дискурс', 'id': 1, 'pic': ''}], } async def update_author(author: Author, ttl=25 * 60 * 60): + payload = json.dumps(author.dict()) redis_key = f'user:{author.user}:author' - await redis.execute('SETEX', redis_key, ttl, json.dumps(author.dict())) + await redis.execute('SETEX', redis_key, ttl, payload) + redis_key = f'author:{author.id}:author' + await redis.execute('SETEX', redis_key, ttl, payload) @event.listens_for(Author, 'after_insert')