[Zope3-checkins] CVS: Zope3/src/zope/app/catalog - catalog.py:1.1.2.2
Anthony Baxter
anthony@interlink.com.au
Sat, 12 Jul 2003 04:40:53 -0400
Update of /cvs-repository/Zope3/src/zope/app/catalog
In directory cvs.zope.org:/tmp/cvs-serv17013/catalog
Modified Files:
Tag: melb-2003-content-catalog-branch
catalog.py
Log Message:
refreshing and clearing indexes now works (the 'refresh' and 'clear'
button on the advanced tab of the catalog.
searchResults now returns a generator (so it behaves like the old Z2
LazyCat, in that it only brings objects in when they're needed).
=== Zope3/src/zope/app/catalog/catalog.py 1.1.2.1 => 1.1.2.2 ===
--- Zope3/src/zope/app/catalog/catalog.py:1.1.2.1 Sat Jul 12 02:15:12 2003
+++ Zope3/src/zope/app/catalog/catalog.py Sat Jul 12 04:40:50 2003
@@ -17,19 +17,24 @@
from zope.app.container.sample import SampleContainer
# gods save us from 5-deep nested pkgs
-import zope.app.interfaces.services.hub as Hub
+import zope.app.interfaces.services.hub as IHub
+import zope.app.services.hub as Hub
import time
from zope.app.interfaces.catalog.catalog import ICatalogView, ICatalog
+def ResultSet(hubidset, hub):
+ for hubid in hubidset:
+ obj = hub.getObject(hubid)
+ yield obj
+
class Catalog(Persistent, SampleContainer):
implements(ICatalog, ISubscriber, IDeleteNotifiable,
IAddNotifiable, IContainer, IAttributeAnnotatable)
_subscribed = False
- _channel = None
def _newContainerData(self):
return PersistentDict()
@@ -38,7 +43,7 @@
return self._subscribed
def afterAddHook(wrapped_self, object, container):
- wrapped_self.subscribeEvents(update=True)
+ wrapped_self.subscribeEvents(update=False)
afterAddHook = ContextMethod(afterAddHook)
def beforeDeleteHook(wrapped_self, object, container):
@@ -48,22 +53,28 @@
beforeDeleteHook = ContextMethod(beforeDeleteHook)
def clearIndexes(self):
- pass
+ for index in self.values():
+ index.clear()
- def updateIndexes(self):
- pass
+ def updateIndexes(wrapped_self):
+ eventF = Hub.ObjectRegisteredHubEvent
+ objectHub = getService(wrapped_self, HubIds)
+ allobj = objectHub.iterObjectRegistrations()
+ for location, hubid, wrapped_object in allobj:
+ eventF(objectHub, hubid, location, wrapped_object)
+ for index in wrapped_self.values():
+ index.notify(eventF)
+ updateIndexes = ContextMethod(updateIndexes)
def subscribeEvents(wrapped_self, update=True):
if wrapped_self._subscribed:
raise ValueError, "Already subscribed"
wrapped_self._subscribed = True
objectHub = getService(wrapped_self, HubIds)
- objectHub.subscribe(wrapped_self, Hub.IRegistrationHubEvent)
- objectHub.subscribe(wrapped_self, Hub.IObjectModifiedHubEvent)
- wrapped_self._channel = objectHub
+ objectHub.subscribe(wrapped_self, IHub.IRegistrationHubEvent)
+ objectHub.subscribe(wrapped_self, IHub.IObjectModifiedHubEvent)
if update:
- allobjs = objectHub.iterObjectRegistrations()
- # pass through the big list to the indexes. bleah.
+ wrapped_self.updateIndexes()
subscribeEvents = ContextMethod(subscribeEvents)
@@ -71,11 +82,10 @@
if not wrapped_self._subscribed:
raise ValueError, "Already unsubscribed"
wrapped_self._subscribed = False
- wrapped_self._channel = None
objectHub = getService(wrapped_self, HubIds)
try:
- objectHub.unsubscribe(wrapped_self, Hub.IRegistrationHubEvent)
- objectHub.unsubscribe(wrapped_self, Hub.IObjectModifiedHubEvent)
+ objectHub.unsubscribe(wrapped_self, IHub.IRegistrationHubEvent)
+ objectHub.unsubscribe(wrapped_self, IHub.IObjectModifiedHubEvent)
except NotFoundError:
# we're not subscribed. bah.
pass
@@ -86,11 +96,11 @@
"somebody loves us! indexes api sucks, we just pass on the event"
indexes = wrapped_self.values()
- if (Hub.IObjectRegisteredHubEvent.isImplementedBy(event) or
- Hub.IObjectModifiedHubEvent.isImplementedBy(event)):
+ if (IHub.IObjectRegisteredHubEvent.isImplementedBy(event) or
+ IHub.IObjectModifiedHubEvent.isImplementedBy(event)):
addobj = event.object
print "got a new object! it's a ", addobj, event.hubid
- elif Hub.IObjectUnregisteredHubEvent.isImplementedBy(event):
+ elif IHub.IObjectUnregisteredHubEvent.isImplementedBy(event):
delobj = event.object
print "got a del object! it's a ", delobj, event.hubid
[ index.notify(event) for index in indexes ]
@@ -99,7 +109,6 @@
index.notify(event)
except:
pass
-
notify = ContextMethod(notify)
def searchResults(wrapped_self, **searchterms):
@@ -117,8 +126,9 @@
if not pendingResults:
# nothing left, short-circuit
break
- # Next we turn the IISet of hubids into an IISet of objects
- results = [ wrapped_self._channel.getObject(x) for x in pendingResults ]
+ # Next we turn the IISet of hubids into a generator of objects
+ objectHub = getService(wrapped_self, HubIds)
+ results = ResultSet(pendingResults, objectHub)
return results
searchResults = ContextMethod(searchResults)