p[]()(0[]

This commit is contained in:
tonyrewin 2022-09-07 20:17:25 +03:00
parent 7e442030fd
commit bd1318dadd
2 changed files with 12 additions and 52 deletions

View File

@ -18,41 +18,41 @@ from sqlalchemy.orm import selectinload
@query.field("topViewed")
async def top_viewed(_, _info, page, size):
async with ShoutsCache.lock:
return ShoutsCache.get_top_viewed()[((page - 1) * size) : (page * size)]
return ShoutsCache.top_viewed[((page - 1) * size) : (page * size)]
@query.field("topMonth")
async def top_month(_, _info, page, size):
async with ShoutsCache.lock:
return ShoutsCache.get_top_month()[((page - 1) * size) : (page * size)]
return ShoutsCache.top_month[((page - 1) * size) : (page * size)]
@query.field("topOverall")
async def top_overall(_, _info, page, size):
async with ShoutsCache.lock:
return ShoutsCache.get_top_overall()[((page - 1) * size) : (page * size)]
return ShoutsCache.top_overall[((page - 1) * size) : (page * size)]
@query.field("recentPublished")
async def recent_published(_, _info, page, size):
async with ShoutsCache.lock:
return ShoutsCache.get_recent_published()[((page - 1) * size) : (page * size)]
return ShoutsCache.recent_published[((page - 1) * size) : (page * size)]
@query.field("recentAll")
async def recent_all(_, _info, page, size):
async with ShoutsCache.lock:
return ShoutsCache.get_recent_all()[((page - 1) * size) : (page * size)]
return ShoutsCache.recent_all[((page - 1) * size) : (page * size)]
@query.field("recentReacted")
async def recent_reacted(_, info, page, size):
async def recent_reacted(_, _info, page, size):
async with ShoutsCache.lock:
return ShoutsCache.get_recent_reacted()[((page - 1) * size) : (page * size)]
return ShoutsCache.recent_reacted[((page - 1) * size) : (page * size)]
@mutation.field("viewShout")
async def view_shout(_, info, slug):
async def view_shout(_, _info, slug):
await ViewedStorage.increment(slug)
return {"error": ""}
@ -84,7 +84,7 @@ async def get_shout_by_slug(_, info, slug):
@query.field("searchQuery")
async def get_search_results(_, info, query, page, size):
async def get_search_results(_, _info, query, page, size):
# TODO: remove the copy of searchByTopics
# with search ranking query
page = page - 1
@ -106,7 +106,7 @@ async def get_search_results(_, info, query, page, size):
@query.field("shoutsByTopics")
async def shouts_by_topics(_, info, slugs, page, size):
async def shouts_by_topics(_, _info, slugs, page, size):
page = page - 1
with local_session() as session:
shouts = (
@ -125,7 +125,7 @@ async def shouts_by_topics(_, info, slugs, page, size):
@query.field("shoutsByCollection")
async def shouts_by_collection(_, info, collection, page, size):
async def shouts_by_collection(_, _info, collection, page, size):
page = page - 1
shouts = []
with local_session() as session:
@ -144,7 +144,7 @@ async def shouts_by_collection(_, info, collection, page, size):
@query.field("shoutsByAuthors")
async def shouts_by_authors(_, info, slugs, page, size):
async def shouts_by_authors(_, _info, slugs, page, size):
page = page - 1
with local_session() as session:

View File

@ -198,46 +198,6 @@ class ShoutsCache:
print("[zine.cache] indexed by %d topics " % len(shouts_by_topic.keys()))
ShoutsCache.by_topic = shouts_by_topic
@staticmethod
async def get_shouts_by_author():
async with ShoutsCache.lock:
return ShoutsCache.by_author
@staticmethod
async def get_shouts_by_topic():
async with ShoutsCache.lock:
return ShoutsCache.by_topic
@staticmethod
async def get_top_overall():
async with ShoutsCache.lock:
return ShoutsCache.by_topic
@staticmethod
async def get_top_month():
async with ShoutsCache.lock:
return ShoutsCache.by_topic
@staticmethod
async def get_top_viewed():
async with ShoutsCache.lock:
return ShoutsCache.by_topic
@staticmethod
async def get_recent_published():
async with ShoutsCache.lock:
return ShoutsCache.recent_published
@staticmethod
async def get_recent_all():
async with ShoutsCache.lock:
return ShoutsCache.recent_all
@staticmethod
async def get_recent_reacted():
async with ShoutsCache.lock:
return ShoutsCache.recent_reacted
@staticmethod
async def worker():
while True: