recent_commented

This commit is contained in:
Tony 2022-02-03 12:13:53 +03:00
parent 6b255cc984
commit dd85d58ccf
2 changed files with 278 additions and 253 deletions

View File

@ -98,6 +98,24 @@ class ShoutsCache:
async with ShoutsCache.lock:
ShoutsCache.recent_shouts = shouts
# TODO: DEBUG ME
@staticmethod
async def prepare_recent_commented():
with local_session() as session:
stmt = select(Shout).\
options(selectinload(Shout.authors), selectinload(Shout.topics)).\
join(Comment).\
where(and_(Shout.publishedAt != None, Comment.publishedAt == User.id)).\
order_by(desc("publishedAt")).\
limit(ShoutsCache.limit)
shouts = []
for row in session.execute(stmt):
shout = row.Shout
shout.ratings = await ShoutRatingStorage.get_ratings(shout.slug)
shouts.append(shout)
async with ShoutsCache.lock:
ShoutsCache.recent_shouts = shouts
@staticmethod
async def prepare_top_overall():
@ -166,6 +184,7 @@ class ShoutsCache:
await ShoutsCache.prepare_top_overall()
await ShoutsCache.prepare_top_viewed()
await ShoutsCache.prepare_recent_shouts()
await ShoutsCache.prepare_recent_commented()
print("shouts cache update finished")
except Exception as err:
print("shouts cache worker error = %s" % (err))
@ -211,6 +230,11 @@ async def recent_shouts(_, info, page, size):
async with ShoutsCache.lock:
return ShoutsCache.recent_shouts[(page - 1) * size : page * size]
@query.field("recentCommented")
async def recent_shouts(_, info, page, size):
async with ShoutsCache.lock:
return ShoutsCache.recent_commented[(page - 1) * size : page * size]
@mutation.field("createShout")
@login_required
async def create_shout(_, info, input):

View File

@ -199,6 +199,7 @@ type Query {
shoutsSubscribed(page: Int!, size: Int!): [Shout]!
shoutsReviewed(page: Int!, size: Int!): [Shout]!
shoutsCommented(page: Int!, size: Int!): [Shout]!
shoutsCandidates(size: Int = 10): [Shout]!
}