not published in feed. devmode try

This commit is contained in:
2022-06-12 01:05:20 +03:00
parent 956dc3915c
commit 8e7e070948
4 changed files with 37 additions and 5 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, top_viewed, shouts_by_authors, shouts_by_topics, shouts_by_communities, \
top_month, top_overall, recent_shouts, 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, \
@@ -20,6 +20,7 @@ __all__ = [
"get_users_by_slugs",
"get_shout_by_slug",
"recent_shouts",
"recent_all",
"shouts_by_topics",
"shouts_by_authors",
"shouts_by_communities",

View File

@@ -98,6 +98,21 @@ class ShoutsCache:
async with ShoutsCache.lock:
ShoutsCache.recent_shouts = 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).\
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_all = shouts
@staticmethod
async def prepare_recent_commented():
with local_session() as session:
@@ -184,6 +199,7 @@ class ShoutsCache:
await ShoutsCache.prepare_top_overall()
await ShoutsCache.prepare_top_viewed()
await ShoutsCache.prepare_recent_shouts()
await ShoutsCache.prepare_recent_all()
await ShoutsCache.prepare_recent_commented()
print("shouts cache update finished")
except Exception as err:
@@ -225,13 +241,18 @@ async def top_overall(_, info, page, size):
async with ShoutsCache.lock:
return ShoutsCache.top_overall[(page - 1) * size : page * size]
@query.field("recents")
@query.field("recentPublished")
async def recent_shouts(_, info, page, size):
async with ShoutsCache.lock:
return ShoutsCache.recent_shouts[(page - 1) * size : page * size]
@query.field("recentAll")
async def recent_all(_, info, page, size):
async with ShoutsCache.lock:
return ShoutsCache.recent_all[(page - 1) * size : page * size]
@query.field("recentCommented")
async def recent_shouts(_, info, page, size):
async def recent_commented(_, info, page, size):
async with ShoutsCache.lock:
return ShoutsCache.recent_commented[(page - 1) * size : page * size]