fix recentAll

This commit is contained in:
knst-kotov 2022-06-12 09:10:00 +03:00
parent 8e7e070948
commit 03c1b69bfb
2 changed files with 8 additions and 8 deletions

View File

@ -1,6 +1,6 @@
from resolvers.auth import login, sign_out, is_email_free, register, confirm
from resolvers.zine import create_shout, get_shout_by_slug, \
top_month, top_overall, recent_shouts, recent_all, top_viewed, shouts_by_authors, shouts_by_topics, shouts_by_communities, \
top_month, top_overall, recent_published, recent_all, top_viewed, shouts_by_authors, shouts_by_topics, shouts_by_communities, \
shouts_candidates, shouts_reviewed, shouts_subscribed
from resolvers.profile import get_users_by_slugs, get_current_user
from resolvers.topics import topic_subscribe, topic_unsubscribe, topics_by_author, \
@ -19,7 +19,7 @@ __all__ = [
"get_current_user",
"get_users_by_slugs",
"get_shout_by_slug",
"recent_shouts",
"recent_published",
"recent_all",
"shouts_by_topics",
"shouts_by_authors",

View File

@ -83,7 +83,7 @@ class ShoutsCache:
lock = asyncio.Lock()
@staticmethod
async def prepare_recent_shouts():
async def prepare_recent_published():
with local_session() as session:
stmt = select(Shout).\
options(selectinload(Shout.authors), selectinload(Shout.topics)).\
@ -96,14 +96,14 @@ class ShoutsCache:
shout.ratings = await ShoutRatingStorage.get_ratings(shout.slug)
shouts.append(shout)
async with ShoutsCache.lock:
ShoutsCache.recent_shouts = shouts
ShoutsCache.recent_published = shouts
@staticmethod
async def prepare_recent_all():
with local_session() as session:
stmt = select(Shout).\
options(selectinload(Shout.authors), selectinload(Shout.topics)).\
where(Shout.publishedAt != None).\
order_by(desc("createdAt")).\
limit(ShoutsCache.limit)
shouts = []
for row in session.execute(stmt):
@ -198,7 +198,7 @@ class ShoutsCache:
await ShoutsCache.prepare_top_month()
await ShoutsCache.prepare_top_overall()
await ShoutsCache.prepare_top_viewed()
await ShoutsCache.prepare_recent_shouts()
await ShoutsCache.prepare_recent_published()
await ShoutsCache.prepare_recent_all()
await ShoutsCache.prepare_recent_commented()
print("shouts cache update finished")
@ -242,9 +242,9 @@ async def top_overall(_, info, page, size):
return ShoutsCache.top_overall[(page - 1) * size : page * size]
@query.field("recentPublished")
async def recent_shouts(_, info, page, size):
async def recent_published(_, info, page, size):
async with ShoutsCache.lock:
return ShoutsCache.recent_shouts[(page - 1) * size : page * size]
return ShoutsCache.recent_published[(page - 1) * size : page * size]
@query.field("recentAll")
async def recent_all(_, info, page, size):