[Zodb-checkins] SVN: ZODB/branches/jim-zeo-blob/src/ZODB/ExportImport.py Sped up and cleaned up blob handling a bit.

Jim Fulton jim at zope.com
Tue May 15 18:29:33 EDT 2007


Log message for revision 75783:
  Sped up and cleaned up blob handling a bit.
  

Changed:
  U   ZODB/branches/jim-zeo-blob/src/ZODB/ExportImport.py

-=-
Modified: ZODB/branches/jim-zeo-blob/src/ZODB/ExportImport.py
===================================================================
--- ZODB/branches/jim-zeo-blob/src/ZODB/ExportImport.py	2007-05-15 22:28:44 UTC (rev 75782)
+++ ZODB/branches/jim-zeo-blob/src/ZODB/ExportImport.py	2007-05-15 22:29:32 UTC (rev 75783)
@@ -39,6 +39,7 @@
         done_oids = {}
         done=done_oids.has_key
         load=self._storage.load
+        supports_blobs = IBlobStorage.providedBy(self._storage)
         while oids:
             oid = oids.pop(0)
             if oid in done_oids:
@@ -52,20 +53,22 @@
             else:
                 referencesf(p, oids)
                 f.writelines([oid, p64(len(p)), p])
-            # Blob support
-            if not IBlobStorage.providedBy(self._storage):
-                continue
-            try:
-                blobfilename = self._storage.loadBlob(oid, 
-                                                      serial, self._version)
-            except POSKeyError: # Looks like this is not a blob
-                continue
 
-            f.write(blob_begin_marker)
-            f.write(p64(os.stat(blobfilename).st_size))
-            blobdata = open(blobfilename, "rb")
-            cp(blobdata, f)
-            blobdata.close()
+            if supports_blobs:
+                if 'Blob' not in p:
+                    continue # filter out most non-blobs
+                
+                blobfilename = self._storage.loadBlob(
+                    oid, serial, self._version)
+                if blobfilename is None:
+                    # This could be a non-blob or a blob with unsaved data.
+                    continue
+
+                f.write(blob_begin_marker)
+                f.write(p64(os.stat(blobfilename).st_size))
+                blobdata = open(blobfilename, "rb")
+                cp(blobdata, f)
+                blobdata.close()
             
         f.write(export_end_marker)
         return f



More information about the Zodb-checkins mailing list