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 b499ac1
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 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,22 @@ class IDisableCatalogIndexing(Interface):

class DeactivatedCatalogIndexing(object):
"""Contextmanager: Deactivates catalog-indexing
Because collective.indexing will still be adding indexing operations
to the indexing queue, and our patch will only apply 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 b499ac1

Please sign in to comment.