sqlfix
Some checks are pending
Deploy to core / deploy (push) Waiting to run

This commit is contained in:
Untone 2024-02-21 18:38:15 +03:00
parent 3ae706d6db
commit 3f361b1af7
2 changed files with 11 additions and 11 deletions

View File

@ -98,8 +98,6 @@ def query_follows(user_id: str):
session.query(aliased_author) session.query(aliased_author)
.join(AuthorFollower, AuthorFollower.follower == author_id) .join(AuthorFollower, AuthorFollower.follower == author_id)
.filter(AuthorFollower.author == aliased_author.id) .filter(AuthorFollower.author == aliased_author.id)
# .options(load_only(aliased_author.id)) # TODO: Exclude unnecessary columns
.dicts()
.all() .all()
) )
@ -107,23 +105,20 @@ def query_follows(user_id: str):
session.query(Topic) session.query(Topic)
.join(TopicFollower, TopicFollower.follower == author_id) .join(TopicFollower, TopicFollower.follower == author_id)
.filter(TopicFollower.topic == Topic.id) .filter(TopicFollower.topic == Topic.id)
# .options(load_only(Topic.id)) # TODO: Exclude unnecessary columns
.dicts()
.all() .all()
) )
# Convert query results to lists of dictionaries # Convert query results to lists of dictionaries
authors = set(authors_query) authors = [author.to_dict() for author in authors_query]
topics = set(topics_query) topics = [topic.to_dict() for topic in topics_query]
# shouts_query = ( # shouts_query = (
# session.query(Shout) # session.query(Shout)
# .join(ShoutReactionsFollower, ShoutReactionsFollower.follower == author_id) # .join(ShoutReactionsFollower, ShoutReactionsFollower.follower == author_id)
# .filter(ShoutReactionsFollower.shout == Shout.id) # .filter(ShoutReactionsFollower.shout == Shout.id)
# .options(load_only(Shout.id)) # Exclude unnecessary columns # .options(load_only(Shout.id)) # Exclude unnecessary columns
# .dicts()
# .all() # .all()
# ) # )
# shouts = list(shouts_query) # shouts = [shout.to_dict() for shout in shouts_query]
# communities = session.query(Community).all() # communities = session.query(Community).all()
return { return {
@ -134,7 +129,6 @@ def query_follows(user_id: str):
} }
async def get_follows_by_user_id(user_id: str): async def get_follows_by_user_id(user_id: str):
if user_id: if user_id:
redis_key = f"user:{user_id}:follows" redis_key = f"user:{user_id}:follows"

View File

@ -124,8 +124,13 @@ class FollowsCached:
authors = session.query(Author).all() authors = session.query(Author).all()
total_authors = len(authors) total_authors = len(authors)
for i in range(0, total_authors, BATCH_SIZE): for i in range(0, total_authors, BATCH_SIZE):
batch_authors = authors[i:i+BATCH_SIZE] batch_authors = authors[i : i + BATCH_SIZE]
await asyncio.gather(*[FollowsCached.update_author_cache(author) for author in batch_authors]) await asyncio.gather(
*[
FollowsCached.update_author_cache(author)
for author in batch_authors
]
)
@staticmethod @staticmethod
async def update_author_cache(author): async def update_author_cache(author):
@ -154,5 +159,6 @@ class FollowsCached:
except Exception as exc: except Exception as exc:
logger.error(exc) logger.error(exc)
async def start_cached_follows(): async def start_cached_follows():
await FollowsCached.worker() await FollowsCached.worker()