[Zodb-checkins] CVS: StandaloneZODB/ZODB - FileStorage.py:1.73

Jeremy Hylton jeremy@zope.com
Wed, 24 Oct 2001 18:31:16 -0400


Update of /cvs-repository/StandaloneZODB/ZODB
In directory cvs.zope.org:/tmp/cvs-serv29257

Modified Files:
	FileStorage.py 
Log Message:
Provide faster implementation of getSerial().

This implementation is only faster for an object that is not modified
in a version.  For an object modified in a version, it should be about
the same as the default getSerial() in BaseStorage.



=== StandaloneZODB/ZODB/FileStorage.py 1.72 => 1.73 ===
         return _loadBack(file, oid, read(8))[0], version, nv
 
+    def getSerial(self, oid):
+        self._lock_acquire()
+        try:
+            pos = self._index[oid]
+            self._file.seek(pos)
+            h = self._file.read(34)
+            _oid = h[:8]
+            if _oid != oid:
+                raise CorruptedData, h
+            vlen = unpack(">H", h[-2:])[0]
+            if vlen:
+                # If there is a version, find out its name and let
+                # _load() do all the work.  This is less efficient
+                # than possible, because _load() will load the pickle
+                # data.  Being more efficient is too complicated.
+                self._file.seek(24, 1) # skip plen, pnv, and pv
+                version = self._file.read(vlen)
+                pickledata, serial = self._load(oid, version,
+                                                self._index, self._file)
+                return serial
+            return h[8:16]
+        finally:
+            self._lock_release()
+        
+
     def _load(self, oid, version, _index, file):
         pos=_index[oid]
         file.seek(pos)