From 1fc46bb450504881fb160a3646523111a71abe26 Mon Sep 17 00:00:00 2001 From: tonyrewin Date: Wed, 14 Sep 2022 14:09:28 +0300 Subject: [PATCH] offset-limit --- resolvers/topics.py | 2 +- resolvers/zine.py | 6 +++--- services/zine/shoutscache.py | 1 + 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/resolvers/topics.py b/resolvers/topics.py index fc42ed4d..29a94767 100644 --- a/resolvers/topics.py +++ b/resolvers/topics.py @@ -91,6 +91,6 @@ async def topics_random(_, info, amount=12): # #if topic_stat["shouts"] > 2: # normalized_topics.append(topic) topic.stat = topic_stat - normalized_topics = topics + normalized_topics.append(topic) sample_length = min(len(normalized_topics), amount) return random.sample(normalized_topics, sample_length) diff --git a/resolvers/zine.py b/resolvers/zine.py index 96d80993..ab290b54 100644 --- a/resolvers/zine.py +++ b/resolvers/zine.py @@ -4,7 +4,7 @@ from orm.topic import Topic from base.orm import local_session from base.resolvers import mutation, query from services.zine.shoutauthor import ShoutAuthorStorage -from services.zine.shoutscache import ShoutsCache, prepare_shouts +from services.zine.shoutscache import ShoutsCache from services.stat.viewed import ViewedStorage from resolvers.profile import author_follow, author_unfollow from resolvers.topics import topic_follow, topic_unfollow @@ -112,7 +112,7 @@ async def get_search_results(_, _info, query, offset, limit): @query.field("shoutsByTopics") async def shouts_by_topics(_, _info, slugs, offset, limit): with local_session() as session: - shouts = prepare_shouts( + shouts = ( session.query(Shout) .join(ShoutTopic) .where(and_(ShoutTopic.topic.in_(slugs), bool(Shout.publishedAt))) @@ -130,7 +130,7 @@ async def shouts_by_topics(_, _info, slugs, offset, limit): @query.field("shoutsByCollection") async def shouts_by_collection(_, _info, collection, offset, limit): with local_session() as session: - shouts = prepare_shouts( + shouts = ( session.query(Shout) .join(ShoutCollection, ShoutCollection.collection == collection) .where(and_(ShoutCollection.shout == Shout.slug, bool(Shout.publishedAt))) diff --git a/services/zine/shoutscache.py b/services/zine/shoutscache.py index cf7294c4..4dfb7079 100644 --- a/services/zine/shoutscache.py +++ b/services/zine/shoutscache.py @@ -39,6 +39,7 @@ class ShoutsCache: .options(selectinload(Shout.authors), selectinload(Shout.topics)) .where(bool(Shout.publishedAt)) .order_by(desc("publishedAt")) + .order_by(desc("createdAt")) .limit(ShoutsCache.limit) )) async with ShoutsCache.lock: