From 873d05e00048432bfedb6b420dfddc98897c0f7a Mon Sep 17 00:00:00 2001 From: knst-kotov Date: Tue, 15 Feb 2022 14:12:54 +0300 Subject: [PATCH] fix recentCommented --- resolvers/zine.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/resolvers/zine.py b/resolvers/zine.py index a354b238..54f0c2dc 100644 --- a/resolvers/zine.py +++ b/resolvers/zine.py @@ -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