unique-fix
This commit is contained in:
parent
c10f416567
commit
037c111b1d
|
@ -111,35 +111,32 @@ async def get_search_results(_, _info, searchtext, offset, limit):
|
||||||
|
|
||||||
@query.field("shoutsByAuthors")
|
@query.field("shoutsByAuthors")
|
||||||
async def shouts_by_authors(_, _info, slugs, offset, limit):
|
async def shouts_by_authors(_, _info, slugs, offset, limit):
|
||||||
shouts = []
|
|
||||||
async with ShoutsCache.lock:
|
async with ShoutsCache.lock:
|
||||||
|
shouts = {}
|
||||||
for author in slugs:
|
for author in slugs:
|
||||||
shouts.extend(ShoutsCache.by_author.get(author, []))
|
for shouts_by_author in ShoutsCache.by_author.get(author, []):
|
||||||
shouts_prepared = []
|
for s in shouts_by_author:
|
||||||
for s in shouts:
|
|
||||||
if bool(s.publishedAt):
|
|
||||||
for a in s.authors:
|
for a in s.authors:
|
||||||
a.caption = await ShoutAuthorStorage.get_author_caption(s.slug, a.slug)
|
a.caption = await ShoutAuthorStorage.get_author_caption(s.slug, a.slug)
|
||||||
if s not in shouts_prepared:
|
if bool(s.publishedAt):
|
||||||
shouts_prepared.append(s)
|
shouts[s.slug] = s
|
||||||
|
shouts_prepared = shouts.values()
|
||||||
shouts_prepared.sort(key=lambda s: s.publishedAt, reverse=True)
|
shouts_prepared.sort(key=lambda s: s.publishedAt, reverse=True)
|
||||||
return shouts_prepared[offset : offset + limit]
|
return shouts_prepared[offset : offset + limit]
|
||||||
|
|
||||||
|
|
||||||
@query.field("shoutsByTopics")
|
@query.field("shoutsByTopics")
|
||||||
async def shouts_by_topics(_, _info, slugs, offset, limit):
|
async def shouts_by_topics(_, _info, slugs, offset=0, limit=100):
|
||||||
shouts = []
|
|
||||||
async with ShoutsCache.lock:
|
async with ShoutsCache.lock:
|
||||||
|
shouts = {}
|
||||||
for topic in slugs:
|
for topic in slugs:
|
||||||
shouts.extend(ShoutsCache.by_topic.get(topic, []))
|
for shouts_by_topic in ShoutsCache.by_topic.get(topic, []):
|
||||||
shouts_prepared = []
|
for s in shouts_by_topic:
|
||||||
for s in shouts:
|
|
||||||
if bool(s.publishedAt):
|
|
||||||
for a in s.authors:
|
for a in s.authors:
|
||||||
a.caption = await ShoutAuthorStorage.get_author_caption(s.slug, a.slug)
|
a.caption = await ShoutAuthorStorage.get_author_caption(s.slug, a.slug)
|
||||||
if s not in shouts_prepared:
|
if bool(s.publishedAt):
|
||||||
shouts_prepared.append(s)
|
shouts[s.slug] = s
|
||||||
shouts_prepared = list(set(shouts_prepared))
|
shouts_prepared = shouts.values()
|
||||||
shouts_prepared.sort(key=lambda s: s.publishedAt, reverse=True)
|
shouts_prepared.sort(key=lambda s: s.publishedAt, reverse=True)
|
||||||
return shouts_prepared[offset : offset + limit]
|
return shouts_prepared[offset : offset + limit]
|
||||||
|
|
||||||
|
|
|
@ -66,9 +66,11 @@ class ShoutsCache:
|
||||||
for s in shouts:
|
for s in shouts:
|
||||||
for a in s.authors:
|
for a in s.authors:
|
||||||
ShoutsCache.by_author[a.slug] = ShoutsCache.by_author.get(a.slug, [])
|
ShoutsCache.by_author[a.slug] = ShoutsCache.by_author.get(a.slug, [])
|
||||||
|
if s not in ShoutsCache.by_author[a.slug]:
|
||||||
ShoutsCache.by_author[a.slug].append(s)
|
ShoutsCache.by_author[a.slug].append(s)
|
||||||
for t in s.topics:
|
for t in s.topics:
|
||||||
ShoutsCache.by_topic[t.slug] = ShoutsCache.by_topic.get(t.slug, [])
|
ShoutsCache.by_topic[t.slug] = ShoutsCache.by_topic.get(t.slug, [])
|
||||||
|
if s not in ShoutsCache.by_topic[t.slug]:
|
||||||
ShoutsCache.by_topic[t.slug].append(s)
|
ShoutsCache.by_topic[t.slug].append(s)
|
||||||
print("[zine.cache] indexed by %d topics " % len(ShoutsCache.by_topic.keys()))
|
print("[zine.cache] indexed by %d topics " % len(ShoutsCache.by_topic.keys()))
|
||||||
print("[zine.cache] indexed by %d authors " % len(ShoutsCache.by_author.keys()))
|
print("[zine.cache] indexed by %d authors " % len(ShoutsCache.by_author.keys()))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user