redis-keys-renamed

This commit is contained in:
Untone 2024-02-29 10:34:22 +03:00
parent 10248ffd8c
commit 5e400a7618
2 changed files with 7 additions and 7 deletions

View File

@ -143,7 +143,7 @@ async def get_author_follows(_, _info, slug='', user=None, author_id=None):
) )
author_id = author_id_result[0] if author_id_result else None author_id = author_id_result[0] if author_id_result else None
if author_id: if author_id:
rkey = f'id:{author_id}:follows-authors' rkey = f'author:{author_id}:follows-authors'
logger.debug(f'getting {author_id} follows authors') logger.debug(f'getting {author_id} follows authors')
cached = await redis.execute('GET', rkey) cached = await redis.execute('GET', rkey)
# logger.debug(f'AUTHOR CACHED {cached}') # logger.debug(f'AUTHOR CACHED {cached}')
@ -152,7 +152,7 @@ async def get_author_follows(_, _info, slug='', user=None, author_id=None):
prepared = [author.dict() for author in authors] prepared = [author.dict() for author in authors]
await redis.execute('SETEX', rkey, 24*60*60, json.dumps(prepared)) await redis.execute('SETEX', rkey, 24*60*60, json.dumps(prepared))
rkey = f'id:{author_id}:follows-topics' rkey = f'author:{author_id}:follows-topics'
cached = await redis.execute('GET', rkey) cached = await redis.execute('GET', rkey)
topics = json.loads(cached) if cached else author_follows_topics(author_id) topics = json.loads(cached) if cached else author_follows_topics(author_id)
if not cached: if not cached:
@ -181,7 +181,7 @@ async def get_author_follows_topics(_, _info, slug='', user=None, author_id=None
author_id = author_id_result[0] if author_id_result else None author_id = author_id_result[0] if author_id_result else None
if author_id: if author_id:
logger.debug(f'getting {author_id} follows topics') logger.debug(f'getting {author_id} follows topics')
rkey = f'id:{author_id}:follows-topics' rkey = f'author:{author_id}:follows-topics'
cached = await redis.execute('GET', rkey) cached = await redis.execute('GET', rkey)
topics = json.loads(cached) if cached else author_follows_topics(author_id) topics = json.loads(cached) if cached else author_follows_topics(author_id)
if not cached: if not cached:
@ -204,7 +204,7 @@ async def get_author_follows_authors(_, _info, slug='', user=None, author_id=Non
author_id = author_id_result[0] if author_id_result else None author_id = author_id_result[0] if author_id_result else None
if author_id: if author_id:
logger.debug(f'getting {author_id} follows authors') logger.debug(f'getting {author_id} follows authors')
rkey = f'id:{author_id}:follows-authors' rkey = f'author:{author_id}:follows-authors'
cached = await redis.execute('GET', rkey) cached = await redis.execute('GET', rkey)
authors = json.loads(cached) if cached else author_follows_authors(author_id) authors = json.loads(cached) if cached else author_follows_authors(author_id)
if not cached: if not cached:
@ -231,7 +231,7 @@ async def get_author_followers(_, _info, slug: str):
author_alias = aliased(Author) author_alias = aliased(Author)
author_id = session.query(author_alias.id).filter(author_alias.slug == slug).scalar() author_id = session.query(author_alias.id).filter(author_alias.slug == slug).scalar()
if author_id: if author_id:
cached = await redis.execute('GET', f'id:{author_id}:followers') cached = await redis.execute('GET', f'author:{author_id}:followers')
results = [] results = []
if not cached: if not cached:
author_follower_alias = aliased(AuthorFollower, name='af') author_follower_alias = aliased(AuthorFollower, name='af')

View File

@ -138,7 +138,7 @@ def after_author_follower_delete(mapper, connection, target: AuthorFollower):
async def update_follows_for_author(follower: Author, entity_type: str, entity: dict, is_insert: bool): async def update_follows_for_author(follower: Author, entity_type: str, entity: dict, is_insert: bool):
ttl = 25 * 60 * 60 ttl = 25 * 60 * 60
redis_key = f'id:{follower.id}:follows-{entity_type}s' redis_key = f'author:{follower.id}:follows-{entity_type}s'
follows_str = await redis.get(redis_key) follows_str = await redis.get(redis_key)
follows = json.loads(follows_str) if follows_str else [] follows = json.loads(follows_str) if follows_str else []
if is_insert: if is_insert:
@ -151,7 +151,7 @@ async def update_follows_for_author(follower: Author, entity_type: str, entity:
async def update_followers_for_author(follower: Author, author: Author, is_insert: bool): async def update_followers_for_author(follower: Author, author: Author, is_insert: bool):
ttl = 25 * 60 * 60 ttl = 25 * 60 * 60
redis_key = f'id:{author.id}:followers' redis_key = f'author:{author.id}:followers'
followers_str = await redis.get(redis_key) followers_str = await redis.get(redis_key)
followers = json.loads(followers_str) if followers_str else [] followers = json.loads(followers_str) if followers_str else []
if is_insert: if is_insert: