Skip to content

Commit

Permalink
Catalog multiplex processor compatibility (#2371)
Browse files Browse the repository at this point in the history
* Handle unset catalog mapping for DX types

* Use similar code as in ProtalCatalogProcessor
  • Loading branch information
ramonski authored Sep 2, 2023
1 parent bed7e68 commit a4d7e06
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
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

0 comments on commit a4d7e06

Please sign in to comment.