Skip to content

Commit

Permalink
use a set intersection to decide which documents to unindex
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdonc committed Apr 8, 2012
1 parent 772f740 commit 5046e21
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
6 changes: 3 additions & 3 deletions substanced/catalog/subscribers.py
@@ -1,3 +1,4 @@
import BTrees
from zope.interface import Interface

from pyramid.events import subscriber
Expand Down Expand Up @@ -33,9 +34,8 @@ def object_will_be_removed(obj, event):
if objectmap is None or catalog is None:
return
objectids = objectmap.pathlookup(obj)
for oid in objectids:
if oid in catalog.objectids:
catalog.unindex_doc(oid)
for oid in BTrees.family32.IF.intersection(objectids, catalog.objectids):
catalog.unindex_doc(oid)

@subscriber([Interface, IObjectModifiedEvent])
def object_modified(obj, event):
Expand Down
9 changes: 4 additions & 5 deletions substanced/catalog/tests/test_subscribers.py
@@ -1,11 +1,10 @@
import unittest
import BTrees

from zope.interface import alsoProvides

from pyramid import testing

from pyramid.traversal import resource_path_tuple

def _makeSite(**kw):
from ...interfaces import IFolder
site = testing.DummyResource(__provides__=kw.pop('__provides__', None))
Expand Down Expand Up @@ -75,7 +74,7 @@ def test_no_catalog(self):
def test_with_pathlookup(self):
model = testing.DummyResource()
catalog = DummyCatalog()
catalog.objectids = [1,2]
catalog.objectids = BTrees.family32.IF.Set([1,2])
objectmap = DummyObjectMap()
site = _makeSite(objectmap=objectmap, catalog=catalog)
site['model'] = model
Expand All @@ -87,7 +86,7 @@ def test_with_pathlookup(self):
def test_with_pathlookup_limited_by_objectids(self):
model = testing.DummyResource()
catalog = DummyCatalog()
catalog.objectids = [1]
catalog.objectids = BTrees.family32.IF.Set([1])
objectmap = DummyObjectMap()
site = _makeSite(objectmap=objectmap, catalog=catalog)
site['model'] = model
Expand Down Expand Up @@ -154,7 +153,7 @@ def reindex_doc(self, objectid, obj):

class DummyObjectMap:
def pathlookup(self, obj):
return [1,2]
return BTrees.family32.IF.Set([1,2])

class DummyEvent(object):
def __init__(self, parent):
Expand Down

0 comments on commit 5046e21

Please sign in to comment.