fix recentCommented

This commit is contained in:
knst-kotov 2022-02-15 14:12:54 +03:00
parent 847240e20f
commit 873d05e000

View File

@ -98,15 +98,15 @@ class ShoutsCache:
async with ShoutsCache.lock:
ShoutsCache.recent_shouts = shouts
# TODO: DEBUG ME
@staticmethod
async def prepare_recent_commented():
with local_session() as session:
stmt = select(Shout).\
stmt = select(Shout, func.max(Comment.createdAt).label("commentCreatedAt")).\
options(selectinload(Shout.authors), selectinload(Shout.topics)).\
join(Comment).\
where(and_(Shout.publishedAt != None, Comment.publishedAt == User.id)).\
order_by(desc("publishedAt")).\
where(and_(Shout.publishedAt != None, Comment.deletedAt == None)).\
group_by(Shout.slug).\
order_by(desc("commentCreatedAt")).\
limit(ShoutsCache.limit)
shouts = []
for row in session.execute(stmt):
@ -114,7 +114,7 @@ class ShoutsCache:
shout.ratings = await ShoutRatingStorage.get_ratings(shout.slug)
shouts.append(shout)
async with ShoutsCache.lock:
ShoutsCache.recent_shouts = shouts
ShoutsCache.recent_commented = shouts
@staticmethod