From 5da27fffa522b7fed9302b3ef761e679cc63dbc4 Mon Sep 17 00:00:00 2001 From: tonyrewin Date: Tue, 4 Oct 2022 17:03:13 +0300 Subject: [PATCH] undublicate --- resolvers/topics.py | 2 +- resolvers/zine.py | 21 +++++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/resolvers/topics.py b/resolvers/topics.py index 5bc90424..9ff2e070 100644 --- a/resolvers/topics.py +++ b/resolvers/topics.py @@ -43,7 +43,7 @@ async def topics_by_community(_, info, community): @query.field("topicsByAuthor") async def topics_by_author(_, _info, author): - shouts = ShoutsCache.by_author.get(author) + shouts = ShoutsCache.by_author.get(author, []) author_topics = set() for s in shouts: for tpc in s.topics: diff --git a/resolvers/zine.py b/resolvers/zine.py index 0680e05e..19082cbb 100644 --- a/resolvers/zine.py +++ b/resolvers/zine.py @@ -115,15 +115,15 @@ async def shouts_by_authors(_, _info, slugs, offset, limit): 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): - for a in s.authors: - a.caption = await ShoutAuthorStorage.get_author_caption(s.slug, a.slug) - shouts_prepared.append(s) - shouts_prepared = list(set(shouts_prepared)) - shouts_prepared.sort(key=lambda s: s.publishedAt, reverse=True) - return shouts_prepared[offset : offset + limit] + shouts_prepared = [] + for s in shouts: + if bool(s.publishedAt): + for a in s.authors: + a.caption = await ShoutAuthorStorage.get_author_caption(s.slug, a.slug) + if s not in shouts_prepared: + shouts_prepared.append(s) + shouts_prepared.sort(key=lambda s: s.publishedAt, reverse=True) + return shouts_prepared[offset : offset + limit] @query.field("shoutsByTopics") @@ -137,7 +137,8 @@ async def shouts_by_topics(_, _info, slugs, offset, limit): if bool(s.publishedAt): for a in s.authors: a.caption = await ShoutAuthorStorage.get_author_caption(s.slug, a.slug) - shouts_prepared.append(s) + if s not in shouts_prepared: + shouts_prepared.append(s) shouts_prepared = list(set(shouts_prepared)) shouts_prepared.sort(key=lambda s: s.publishedAt, reverse=True) return shouts_prepared[offset : offset + limit]