Skip to content

Commit

Permalink
Refactor post_authors indexer to avoid repeated calls to the catalog (#…
Browse files Browse the repository at this point in the history
…57)

* Refactor post_authors indexer to avoid repeated calls to the catalog

* Update src/collective/blog/indexers/post.py

Co-authored-by: David Glick <david@glicksoftware.com>

* fix upgrade steps

---------

Co-authored-by: Jonas Piterek <110389276+jonaspiterek@users.noreply.github.com>
Co-authored-by: David Glick <david@glicksoftware.com>
Co-authored-by: jonaspiterek <piterek@kitconcept.com>
  • Loading branch information
4 people authored Feb 2, 2024
1 parent 2a534ea commit f3c7a2d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
1 change: 1 addition & 0 deletions news/56.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Refactor post_authors indexer to avoid repeated calls to the catalog
11 changes: 3 additions & 8 deletions src/collective/blog/indexers/post.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@ def post_authors(obj: Post):
"""Returns the authors of a blog post."""
authors = []
uids = obj.creators
for uid in uids:
searchResult = api.content.find(portal_type="Author", UID=uid)
if len(searchResult) > 0:
author = searchResult[0].getObject()

if author is not None:
authors.append(author.title)

brains = api.content.find(portal_type="Author", UID=uids)
for brain in brains:
authors.append(brain.Title)
return authors
2 changes: 1 addition & 1 deletion src/collective/blog/upgrades/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
/>
<genericsetup:upgradeDepends
title="Blog type: Set global_allow to true"
import_steps="types"
import_steps="typeinfo"
/>
</genericsetup:upgradeSteps>
</configure>

0 comments on commit f3c7a2d

Please sign in to comment.