query-fixes
This commit is contained in:
parent
e23c49b6c6
commit
1c7729a5b9
|
@ -33,7 +33,7 @@ async def update_author_followers_cache(author_id: int, followers):
|
||||||
|
|
||||||
async def set_follows_topics_cache(follows, author_id: int):
|
async def set_follows_topics_cache(follows, author_id: int):
|
||||||
try:
|
try:
|
||||||
payload = json.dumps(follows, cls=CustomJSONEncoder)
|
payload = json.dumps([a.dict() for a in follows], cls=CustomJSONEncoder)
|
||||||
await redis.execute('SET', f'author:{author_id}:follows-topics', payload)
|
await redis.execute('SET', f'author:{author_id}:follows-topics', payload)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
logger.error(exc)
|
logger.error(exc)
|
||||||
|
@ -45,7 +45,7 @@ async def set_follows_topics_cache(follows, author_id: int):
|
||||||
|
|
||||||
async def set_follows_authors_cache(follows, author_id: int):
|
async def set_follows_authors_cache(follows, author_id: int):
|
||||||
try:
|
try:
|
||||||
payload = json.dumps(follows, cls=CustomJSONEncoder)
|
payload = json.dumps([a.dict() for a in follows], cls=CustomJSONEncoder)
|
||||||
await redis.execute('SET', f'author:{author_id}:follows-authors', payload)
|
await redis.execute('SET', f'author:{author_id}:follows-authors', payload)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
import traceback
|
import traceback
|
||||||
|
@ -184,7 +184,7 @@ async def handle_author_follower_change(
|
||||||
author_query = select(Author).select_from(Author).filter(Author.id == author_id)
|
author_query = select(Author).select_from(Author).filter(Author.id == author_id)
|
||||||
[author] = get_with_stat(author_query)
|
[author] = get_with_stat(author_query)
|
||||||
follower_query = select(Author).select_from(Author).filter(Author.id == follower_id)
|
follower_query = select(Author).select_from(Author).filter(Author.id == follower_id)
|
||||||
follower = get_with_stat(follower_query)
|
[follower] = get_with_stat(follower_query)
|
||||||
if follower and author:
|
if follower and author:
|
||||||
_ = asyncio.create_task(set_author_cache(author.dict()))
|
_ = asyncio.create_task(set_author_cache(author.dict()))
|
||||||
follows_authors = await redis.execute(
|
follows_authors = await redis.execute(
|
||||||
|
@ -215,11 +215,10 @@ async def handle_author_follower_change(
|
||||||
async def handle_topic_follower_change(
|
async def handle_topic_follower_change(
|
||||||
connection, topic_id: int, follower_id: int, is_insert: bool
|
connection, topic_id: int, follower_id: int, is_insert: bool
|
||||||
):
|
):
|
||||||
q = select(Topic).filter(Topic.id == topic_id)
|
topic_query = select(Topic).filter(Topic.id == topic_id)
|
||||||
topics = get_with_stat(q)
|
[topic] = get_with_stat(topic_query)
|
||||||
topic = topics[0]
|
|
||||||
follower_query = select(Author).filter(Author.id == follower_id)
|
follower_query = select(Author).filter(Author.id == follower_id)
|
||||||
follower = get_with_stat(follower_query)
|
[follower] = get_with_stat(follower_query)
|
||||||
if follower and topic:
|
if follower and topic:
|
||||||
_ = asyncio.create_task(set_author_cache(follower.dict()))
|
_ = asyncio.create_task(set_author_cache(follower.dict()))
|
||||||
follows_topics = await redis.execute(
|
follows_topics = await redis.execute(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user