Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catalog multiplex processor compatibility #2371

Merged
merged 2 commits into from
Sep 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 19 additions & 14 deletions src/senaite/core/catalog/catalog_multiplex_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ def supports_multi_catalogs(self, obj):
return True

def index(self, obj, attributes=None):
if attributes is None:
attributes = []

if not self.supports_multi_catalogs(obj):
return

Expand All @@ -79,18 +76,26 @@ def index(self, obj, attributes=None):
logger.info(
"CatalogMultiplexProcessor::indexObject:catalog={} url={}"
.format(catalog.id, url))
# We want the intersection of the catalogs idxs
# and the incoming list.
indexes = set(catalog.indexes()).intersection(attributes)
# Skip reindexing if no indexes match
if attributes and not indexes:
continue
# recatalog the object
catalog.catalog_object(obj, url, idxs=list(indexes))
catalog._indexObject(obj)

def reindex(self, obj, attributes=None, update_metadata=1):
# XXX: Do we need the additional `update_metadata` parameter?
self.index(obj, attributes)
if attributes is None:
attributes = []

if not self.supports_multi_catalogs(obj):
return

catalogs = self.get_catalogs_for(obj)
url = api.get_path(obj)

for catalog in catalogs:
logger.info(
"CatalogMultiplexProcessor::reindexObject:catalog={} url={}"
.format(catalog.id, url))
# Intersection of the catalogs indexes and the incoming attributes
indexes = list(set(catalog.indexes()).intersection(attributes))
catalog._reindexObject(
obj, idxs=indexes, update_metadata=update_metadata)

def unindex(self, obj):
wrapped_obj = obj
Expand All @@ -110,7 +115,7 @@ def unindex(self, obj):
logger.info(
"CatalogMultiplexProcessor::unindex:catalog={} url={}"
.format(catalog.id, url))
catalog.uncatalog_object(url)
catalog._unindexObject(wrapped_obj)

def begin(self):
pass
Expand Down
4 changes: 4 additions & 0 deletions src/senaite/core/patches/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ def in_portal_catalog(obj):

# already handled in our catalog multiplex processor
if IMultiCatalogBehavior.providedBy(obj):
# BBB: Fallback for unset catalogs mapping, e.g. for DataBoxes
catalogs = getattr(obj, "_catalogs", [])
if len(catalogs) == 0:
return True
return False

# check our static mapping from setuphandlers
Expand Down