fix recentAll
This commit is contained in:
@@ -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):
|
||||
|
Reference in New Issue
Block a user