offset-limit
This commit is contained in:
parent
66cd20514e
commit
1fc46bb450
|
@ -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)
|
||||
|
|
|
@ -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)))
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue
Block a user