From 6b4c00d9e749c40cb3564f19a62184b258f78f45 Mon Sep 17 00:00:00 2001 From: tonyrewin Date: Wed, 14 Sep 2022 18:56:49 +0300 Subject: [PATCH] minor fixes --- resolvers/topics.py | 2 +- resolvers/zine.py | 12 ++++++------ services/stat/topicstat.py | 19 +++++++++---------- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/resolvers/topics.py b/resolvers/topics.py index 29a94767..45e3cc53 100644 --- a/resolvers/topics.py +++ b/resolvers/topics.py @@ -10,7 +10,7 @@ from services.zine.shoutscache import ShoutsCache @query.field("topicsAll") -async def topics_all(_, info): +async def topics_all(_, _info): topics = await TopicStorage.get_topics_all() for topic in topics: topic.stat = await TopicStat.get_stat(topic.slug) diff --git a/resolvers/zine.py b/resolvers/zine.py index ab290b54..a0e9ea9f 100644 --- a/resolvers/zine.py +++ b/resolvers/zine.py @@ -11,7 +11,7 @@ from resolvers.topics import topic_follow, topic_unfollow from resolvers.community import community_follow, community_unfollow from resolvers.reactions import reactions_follow, reactions_unfollow from auth.authenticate import login_required -from sqlalchemy import select, desc, and_ +from sqlalchemy import select, desc, asc, and_ from sqlalchemy.orm import selectinload @@ -42,7 +42,7 @@ async def top_overall(_, _info, offset, limit): @query.field("recentPublished") async def recent_published(_, _info, offset, limit): async with ShoutsCache.lock: - return ShoutsCache.top_overall[offset : offset + limit] + return ShoutsCache.recent_published[offset : offset + limit] @query.field("recentAll") @@ -54,7 +54,7 @@ async def recent_all(_, _info, offset, limit): @query.field("recentReacted") async def recent_reacted(_, _info, offset, limit): async with ShoutsCache.lock: - return ShoutsCache.recent_all[offset : offset + limit] + return ShoutsCache.recent_reacted[offset : offset + limit] @mutation.field("viewShout") @@ -116,7 +116,7 @@ async def shouts_by_topics(_, _info, slugs, offset, limit): session.query(Shout) .join(ShoutTopic) .where(and_(ShoutTopic.topic.in_(slugs), bool(Shout.publishedAt))) - .order_by(desc(Shout.publishedAt)) + .order_by(asc(Shout.publishedAt)) .limit(limit) .offset(offset) ) @@ -134,7 +134,7 @@ async def shouts_by_collection(_, _info, collection, offset, limit): session.query(Shout) .join(ShoutCollection, ShoutCollection.collection == collection) .where(and_(ShoutCollection.shout == Shout.slug, bool(Shout.publishedAt))) - .order_by(desc(Shout.publishedAt)) + .order_by(asc(Shout.publishedAt)) .limit(limit) .offset(offset) ) @@ -151,7 +151,7 @@ async def shouts_by_authors(_, _info, slugs, offset, limit): session.query(Shout) .join(ShoutAuthor) .where(and_(ShoutAuthor.user.in_(slugs), bool(Shout.publishedAt))) - .order_by(desc(Shout.publishedAt)) + .order_by(asc(Shout.publishedAt)) .limit(limit) .offset(offset) ) diff --git a/services/stat/topicstat.py b/services/stat/topicstat.py index 03aa1a57..cd50d5a5 100644 --- a/services/stat/topicstat.py +++ b/services/stat/topicstat.py @@ -70,16 +70,15 @@ class TopicStat: shouts = self.shouts_by_topic.get(topic, []) followers = self.followers_by_topic.get(topic, []) authors = self.authors_by_topic.get(topic, []) - - return { - "shouts": len(shouts), - "authors": len(authors), - "followers": len(followers), - "viewed": await ViewedStorage.get_topic(topic), - "reacted": len(await ReactedStorage.get_topic(topic)), - "commented": len(await ReactedStorage.get_topic_comments(topic)), - "rating": await ReactedStorage.get_topic_rating(topic), - } + return { + "shouts": len(shouts), + "authors": len(authors), + "followers": len(followers), + "viewed": await ViewedStorage.get_topic(topic), + "reacted": len(await ReactedStorage.get_topic(topic)), + "commented": len(await ReactedStorage.get_topic_comments(topic)), + "rating": await ReactedStorage.get_topic_rating(topic), + } @staticmethod async def worker():