diff --git a/resolvers/author.py b/resolvers/author.py index 44e1aec4..d5e59a38 100644 --- a/resolvers/author.py +++ b/resolvers/author.py @@ -162,14 +162,14 @@ async def get_author_follows(_, _info, slug='', user=None, author_id=None): ) if not cached: prepared = [author.dict() for author in authors] - await redis.execute('SET', rkey, 24 * 60 * 60, json.dumps(prepared, cls=CustomJSONEncoder)) + await redis.execute('SET', rkey, json.dumps(prepared, cls=CustomJSONEncoder)) rkey = f'author:{author_id}:follows-topics' cached = await redis.execute('GET', rkey) topics = json.loads(cached) if cached else author_follows_topics(author_id) if not cached: prepared = [topic.dict() for topic in topics] - await redis.execute('SET', rkey, 24 * 60 * 60, json.dumps(prepared, cls=CustomJSONEncoder)) + await redis.execute('SET', rkey, json.dumps(prepared, cls=CustomJSONEncoder)) return { 'topics': topics, 'authors': authors, @@ -198,7 +198,7 @@ async def get_author_follows_topics(_, _info, slug='', user=None, author_id=None topics = json.loads(cached) if cached else author_follows_topics(author_id) if not cached: prepared = [topic.dict() for topic in topics] - await redis.execute('SET', rkey, 24 * 60 * 60, json.dumps(prepared, cls=CustomJSONEncoder)) + await redis.execute('SET', rkey, json.dumps(prepared, cls=CustomJSONEncoder)) return topics else: raise ValueError('Author not found') @@ -223,7 +223,7 @@ async def get_author_follows_authors(_, _info, slug='', user=None, author_id=Non ) if not cached: prepared = [author.dict() for author in authors] - await redis.execute('SET', rkey, 24 * 60 * 60, json.dumps(prepared, cls=CustomJSONEncoder)) + await redis.execute('SET', rkey, json.dumps(prepared, cls=CustomJSONEncoder)) return authors else: raise ValueError('Author not found') diff --git a/services/cache.py b/services/cache.py index e536cee9..8771229e 100644 --- a/services/cache.py +++ b/services/cache.py @@ -20,21 +20,21 @@ DEFAULT_FOLLOWS = { } -async def set_author_cache(author: dict, ttl=25 * 60 * 60): +async def set_author_cache(author: dict): payload = json.dumps(author, cls=CustomJSONEncoder) - await redis.execute('SET', f'user:{author.get("user")}:author', ttl, payload) - await redis.execute('SET', f'id:{author.get("id")}:author', ttl, payload) + await redis.execute('SET', f'user:{author.get("user")}:author', payload) + await redis.execute('SET', f'id:{author.get("id")}:author', payload) -async def update_author_followers_cache(author_id: int, followers, ttl=25 * 60 * 60): +async def update_author_followers_cache(author_id: int, followers): payload = json.dumps(followers, cls=CustomJSONEncoder) - await redis.execute('SET', f'author:{author_id}:followers', ttl, payload) + await redis.execute('SET', f'author:{author_id}:followers', payload) -async def set_follows_topics_cache(follows, author_id: int, ttl=25 * 60 * 60): +async def set_follows_topics_cache(follows, author_id: int): try: payload = json.dumps(follows, cls=CustomJSONEncoder) - await redis.execute('SET', f'author:{author_id}:follows-topics', ttl, payload) + await redis.execute('SET', f'author:{author_id}:follows-topics', payload) except Exception as exc: logger.error(exc) import traceback @@ -43,15 +43,14 @@ async def set_follows_topics_cache(follows, author_id: int, ttl=25 * 60 * 60): logger.error(exc) -async def set_follows_authors_cache(follows, author_id: int, ttl=25 * 60 * 60): +async def set_follows_authors_cache(follows, author_id: int): try: payload = json.dumps(follows, cls=CustomJSONEncoder) - await redis.execute( - 'SET', f'author:{author_id}:follows-authors', ttl, payload - ) - except Exception: + await redis.execute('SET', f'author:{author_id}:follows-authors', payload) + except Exception as exc: import traceback + logger.error(exc) exc = traceback.format_exc() logger.error(exc)