[Zope-Checkins] CVS: Zope/lib/python/Products/ZCatalog - Catalog.py:1.111.2.2

Chris McDonough chrism at zope.com
Sun Oct 5 10:09:10 EDT 2003


Update of /cvs-repository/Zope/lib/python/Products/ZCatalog
In directory cvs.zope.org:/tmp/cvs-serv23243

Modified Files:
      Tag: Zope-2_7-branch
	Catalog.py 
Log Message:
Merge 'dont-update-metadata' fix from 2.6 branch.  When the caller specifies that only a particular set of indexes should be updated, don't update the object metadata unconditionally.


=== Zope/lib/python/Products/ZCatalog/Catalog.py 1.111.2.1 => 1.111.2.2 ===
--- Zope/lib/python/Products/ZCatalog/Catalog.py:1.111.2.1	Mon Jul 21 12:36:25 2003
+++ Zope/lib/python/Products/ZCatalog/Catalog.py	Sun Oct  5 10:08:39 2003
@@ -287,35 +287,14 @@
         """ get an index wrapped in the catalog """
         return self.indexes[name].__of__(self)
 
-    # the cataloging API
-
-    def catalogObject(self, object, uid, threshold=None,idxs=[]):
-        """
-        Adds an object to the Catalog by iteratively applying it
-        all indexes.
-
-        'object' is the object to be cataloged
-
-        'uid' is the unique Catalog identifier for this object
-
-        """
-
+    def updateMetadata(self, object, uid):
+        """ Given an object and a uid, update the column data for the
+        uid with the object data iff the object has changed """
         data = self.data
-
-        # meta_data is stored as a tuple for efficiency
+        index = self.uids.get(uid, None)
         newDataRecord = self.recordify(object)
 
-        index=self.uids.get(uid, None)
-        if index is not None:
-            # old data
-
-            if data.get(index, 0) != newDataRecord:
-                # Update the meta-data, if necessary
-                data[index] = newDataRecord
-
-        else:
-            # new data
-
+        if index is None:
             if type(data) is IOBTree:
                 # New style, get random id
 
@@ -340,13 +319,48 @@
                     index = data.keys()[-1] + 1
                 else:
                     index=0
+                # meta_data is stored as a tuple for efficiency
                 data[index] = newDataRecord
+        else:
+            if data.get(index, 0) != newDataRecord:
+                data[index] = newDataRecord
+        return index
+        
+    # the cataloging API
+
+    def catalogObject(self, object, uid, threshold=None,idxs=None):
+        """
+        Adds an object to the Catalog by iteratively applying it
+        all indexes.
+
+        'object' is the object to be cataloged
+
+        'uid' is the unique Catalog identifier for this object
+
+        """
+
+        if idxs is None:
+            idxs = []
+
+        data = self.data
+        index = self.uids.get(uid, None)
+
+        if index is None:  # we are inserting new data
+            index = self.updateMetadata(object, uid)
 
             try: self.__len__.change(1)
             except AttributeError: pass # No managed length (old-style)
 
             self.uids[uid] = index
             self.paths[index] = uid
+
+        else:  # we are updating old data
+            if not idxs:
+                # if the caller specifies that we should update only a
+                # specific set of indexes, we don't do a metadata update.
+                self.updateMetadata(object, uid)
+
+        # do indexing
 
         total = 0
 




More information about the Zope-Checkins mailing list