[Checkins] SVN: relstorage/trunk/relstorage/adapters/packundo.py Simplify object references loading.
Martijn Pieters
mj at zopatista.com
Mon May 23 08:13:24 EDT 2011
Log message for revision 121771:
Simplify object references loading.
Using the groupby abstraction is much more readable here, and the set(generator) construction is also about twice as fast as a for loop with set.add() on each element.
Changed:
U relstorage/trunk/relstorage/adapters/packundo.py
-=-
Modified: relstorage/trunk/relstorage/adapters/packundo.py
===================================================================
--- relstorage/trunk/relstorage/adapters/packundo.py 2011-05-23 11:57:06 UTC (rev 121770)
+++ relstorage/trunk/relstorage/adapters/packundo.py 2011-05-23 12:13:24 UTC (rev 121771)
@@ -15,6 +15,8 @@
"""
from base64 import decodestring
+from itertools import groupby
+from operator import itemgetter
from relstorage.adapters.interfaces import IPackUndo
from ZODB.POSException import UndoError
from zope.interface import implements
@@ -81,18 +83,9 @@
ORDER BY object_ref.zoid
"""
self.runner.run_script_stmt(cursor, stmt)
- current_oid = None
- for from_oid, to_oid in cursor:
- if current_oid is None:
- current_oid = from_oid
- current_refs = set() # set([to_oid])
- elif current_oid != from_oid:
- all_refs[current_oid] = current_refs
- current_oid = from_oid
- current_refs = set()
- current_refs.add(to_oid)
- if current_oid is not None:
- all_refs[current_oid] = current_refs
+ # Grouped by object_ref.zoid, store all object_ref.to_zoid in sets
+ for from_oid, rows in groupby(cursor, itemgetter(0)):
+ all_refs[from_oid] = set(row[1] for row in rows)
# Traverse the object graph. Add all of the reachable OIDs
# to keep_set.
More information about the checkins
mailing list