From 2e2dc8071816530159d0145556514d12aec0acb3 Mon Sep 17 00:00:00 2001 From: Untone Date: Thu, 30 May 2024 20:23:32 +0300 Subject: [PATCH] cache-fix-7 --- services/cache.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/services/cache.py b/services/cache.py index 6826b489..eb987607 100644 --- a/services/cache.py +++ b/services/cache.py @@ -184,14 +184,15 @@ async def get_cached_follower_topics(author_id: int): if cached and isinstance(cached, str): topics_ids = json.loads(cached) else: - topics = ( - local_session() - .query(Topic) - .select_from(join(Topic, TopicFollower, Topic.id == TopicFollower.topic)) - .where(TopicFollower.follower == author_id) - .all() - ) - topics_ids = [topic.id for topic in topics] + with local_session() as session: + topics = ( + session.query(Topic) + .select_from(join(Topic, TopicFollower, Topic.id == TopicFollower.topic)) + .where(TopicFollower.follower == author_id) + .all() + ) + + topics_ids = [topic.id for topic in topics] await redis.execute("SET", rkey, json.dumps(topics_ids)) if not topics: