ratings-true
All checks were successful
Deploy on push / deploy (push) Successful in 1m42s

This commit is contained in:
2024-02-24 19:12:35 +03:00
parent 003fa1bbac
commit 3e58164ae8
3 changed files with 65 additions and 58 deletions

View File

@@ -16,18 +16,16 @@ DEFAULT_FOLLOWS = {
}
async def update_author(author: Author, ttl=25 * 60 * 60):
async def update_author_cache(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, payload)
redis_key = f'author:{author.id}:author'
await redis.execute('SETEX', redis_key, ttl, payload)
await redis.execute('SETEX', f'user:{author.user}:author', ttl, payload)
await redis.execute('SETEX', f'id:{author.user}:author', ttl, payload)
@event.listens_for(Author, 'after_insert')
@event.listens_for(Author, 'after_update')
def after_author_update(mapper, connection, author: Author):
asyncio.create_task(update_author(author))
asyncio.create_task(update_author_cache(author))
@event.listens_for(TopicFollower, 'after_insert')