[Zope-CVS] CVS: Products/Ape/lib/apelib/sql - structure.py:1.7

Shane Hathaway shane at zope.com
Tue Feb 17 00:25:43 EST 2004


Update of /cvs-repository/Products/Ape/lib/apelib/sql
In directory cvs.zope.org:/tmp/cvs-serv17338/lib/apelib/sql

Modified Files:
	structure.py 
Log Message:
Another big pile of changes resulted from a little time. :-)

>From CHANGES.txt:

  - Removed the concepts of "classified state" and "hints", now
    relying on the existing concepts of classification and state.  This
    primarily involved changes to classifiers and the apelib.core.io
    module.

  - Implemented the folder item classification optimization.  Now,
    when Ape loads a folder, it passes along the classification of each
    subitem as part of the containing folder's state.  This means fewer
    round-trips.

Also fixed a couple of shallow bugs that prevented Ape from starting in 
Zope.



=== Products/Ape/lib/apelib/sql/structure.py 1.6 => 1.7 ===
--- Products/Ape/lib/apelib/sql/structure.py:1.6	Mon Feb  2 10:07:21 2004
+++ Products/Ape/lib/apelib/sql/structure.py	Tue Feb 17 00:25:12 2004
@@ -63,6 +63,7 @@
     schema = RowSequenceSchema()
     schema.addField('key', 'string', 1)
     schema.addField('oid', 'string')
+    schema.addField('classification', 'classification')
 
     table_base_name = 'folder_items'
 
@@ -72,17 +73,24 @@
         )
 
     def load(self, event):
-        rows = self.execute(event, 'read', 1, oid=event.oid)
-        rows.sort()
-        res = [(row[0], str(row[1])) for row in rows]
-        return res, tuple(res)
+        rows = list(self.execute(event, 'read', 1, oid=event.oid))
+        res = []
+        h = []
+        for name, child_oid in rows:
+            # XXX This would be faster if we used a join.
+            child_oid = str(child_oid)
+            classification = event.classify(child_oid)
+            res.append((name, child_oid, classification))
+            h.append((name, child_oid))
+        h.sort()
+        return res, tuple(h)
 
     def store(self, event, state):
         state_dict = {}
-        for name, child_oid in state:
+        for name, child_oid, classification in state:
             state_dict[name] = 1
 
-        rows = self.execute(event, 'read', 1, oid=event.oid)
+        rows = list(self.execute(event, 'read', 1, oid=event.oid))
         db_dict = {}
         for name, child_oid in rows:
             if state_dict.has_key(name):
@@ -91,9 +99,9 @@
                 # Remove this item from the database.
                 self.execute(event, 'delete', oid=event.oid, name=name)
 
-        state = list(state)
-        state.sort()
-        for name, child_oid in state:
+        res = []
+        for name, child_oid, classification in state:
+            res.append((name, child_oid))
             kw = {'oid': event.oid, 'name': name, 'child_oid': child_oid}
             if db_dict.has_key(name):
                 if db_dict[name] != child_oid:
@@ -102,7 +110,8 @@
             else:
                 # Add this item to the database.
                 self.execute(event, 'insert', **kw)
-        return tuple(state)
+        res.sort()
+        return tuple(res)
 
 
 class SQLItemId (SQLGatewayBase):
@@ -180,4 +189,3 @@
             # insert.
             self.execute(event, 'insert', **kw)
         return state
-




More information about the Zope-CVS mailing list