From 420d6c1f2d7fcb1cf31c613433469b1dbb91f2ce Mon Sep 17 00:00:00 2001 From: tonyrewin Date: Sat, 1 Oct 2022 13:37:24 +0300 Subject: [PATCH] fix-async --- resolvers/zine.py | 10 ++++++---- services/zine/shoutscache.py | 10 ---------- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/resolvers/zine.py b/resolvers/zine.py index faea6d8b..38b5077c 100644 --- a/resolvers/zine.py +++ b/resolvers/zine.py @@ -120,8 +120,9 @@ async def get_search_results(_, _info, searchtext, offset, limit): @query.field("shoutsByAuthors") async def shouts_by_authors(_, _info, slugs, offset, limit): shouts = [] - for author in slugs: - shouts.extend(await ShoutsCache.get_by_author(author)) + async with ShoutsCache.lock: + for author in slugs: + shouts.extend(ShoutsCache.by_author.get(author, [])) shouts_prepared = [] for s in shouts: if bool(s.publishedAt): @@ -135,8 +136,9 @@ async def shouts_by_authors(_, _info, slugs, offset, limit): @query.field("shoutsByTopics") async def shouts_by_topics(_, _info, slugs, offset, limit): shouts = [] - for topic in slugs: - shouts.extend(await ShoutsCache.get_by_topic(topic)) + async with ShoutsCache.lock: + for topic in slugs: + shouts.extend(ShoutsCache.by_topic.get(topic, [])) shouts_prepared = [] for s in shouts: if bool(s.publishedAt): diff --git a/services/zine/shoutscache.py b/services/zine/shoutscache.py index d72dd50c..90789ed3 100644 --- a/services/zine/shoutscache.py +++ b/services/zine/shoutscache.py @@ -244,16 +244,6 @@ class ShoutsCache: print("[zine.cache] indexed by %d authors " % len(shouts_by_author.keys())) ShoutsCache.by_author = shouts_by_author - @staticmethod - async def get_by_author(author): - async with ShoutsCache.lock: - return ShoutsCache.by_author.get(author, []) - - @staticmethod - async def get_by_topic(topic): - async with ShoutsCache.lock: - return ShoutsCache.by_topic.get(topic, []) - @staticmethod async def get_top_published_before(daysago, offset, limit): shouts_by_rating = []