Skip to content

Commit

Permalink
Fix DeactivatedCatalogIndexing context-manager.
Browse files Browse the repository at this point in the history
Because collective.indexing will still be adding indexing operations
to the indexing queue, and our patch will only apply when the queue is
processed, we need to make sure to process the queue when
entering this context manager so that items already in the queue get
processed correctly, and before exiting the context manager so that
indexing of queued items really gets skipped.
  • Loading branch information
Niklaus Johner committed Mar 24, 2021
1 parent 930fe22 commit 55f1be2
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion opengever/base/monkey/patches/cmf_catalog_aware.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from collective.indexing.queue import processQueue
from opengever.base import _
from opengever.base.monkey.patching import MonkeyPatch
from opengever.base.role_assignments import RoleAssignmentManager
Expand All @@ -7,7 +8,6 @@
from zope.interface import alsoProvides
from zope.interface import Interface
from zope.interface import noLongerProvides
from zope.i18n import translate


class IDisableCatalogIndexing(Interface):
Expand All @@ -24,11 +24,24 @@ class IDisableCatalogIndexing(Interface):

class DeactivatedCatalogIndexing(object):
"""Contextmanager: Deactivates catalog-indexing
Because we Monkey patch the same indexing methods than collective.indexing
and our patch gets applied first, the patch from collective.indexing will
still be adding indexing operations to the indexing queue, and our patched
methods will only be used when the queue is processed.
This is why we need to make sure to process the queue when entering
this context manager so that items already in the queue get processed
correctly, and before exiting the context manager so that indexing of
queued items really gets skipped.
"""
def __enter__(self):
# Because collective indexing will still be adding the indexing
# operations in the queue
processQueue()
alsoProvides(getRequest(), IDisableCatalogIndexing)

def __exit__(self, exc_type, exc_val, exc_tb):
processQueue()
noLongerProvides(getRequest(), IDisableCatalogIndexing)


Expand Down

0 comments on commit 55f1be2

Please sign in to comment.