[Sugar-devel] [PATCH sugar-datastore] Avoid recalculating checksum on metadata-only update

Sascha Silbe silbe at activitycentral.com
Sat Mar 5 17:25:37 EST 2011


If an empty file path has been passed (indicating a metadata-only update),
there is no need to read the potentially huge data file and recalculate its
checksum.

Signed-off-by: Sascha Silbe <silbe at activitycentral.com>
---
 src/carquinyol/datastore.py |   26 +++++++++++++++++++++-----
 1 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/src/carquinyol/datastore.py b/src/carquinyol/datastore.py
index 59c94fa..4f3faba 100644
--- a/src/carquinyol/datastore.py
+++ b/src/carquinyol/datastore.py
@@ -229,15 +229,17 @@ class DataStore(dbus.service.Object):
     def Created(self, uid):
         pass
 
-    def _update_completion_cb(self, async_cb, async_err_cb, uid, exc=None):
-        logger.debug('_update_completion_cb() called with %r / %r, exc %r',
-            async_cb, async_err_cb, exc)
+    def _update_completion_cb(self, async_cb, async_err_cb, uid, exc=None,
+                              need_optimizer_run=True):
+        logger.debug('_update_completion_cb(uid=%r, exc=%r)', uid, exc)
         if exc is not None:
             async_err_cb(exc)
             return
 
         self.Updated(uid)
-        self._optimizer.optimize(uid)
+        if need_optimizer_run:
+            self._optimizer.optimize(uid)
+
         logger.debug('updated %s', uid)
         async_cb()
 
@@ -273,12 +275,26 @@ class DataStore(dbus.service.Object):
             else:
                 props['filesize'] = 0
 
+        if not file_path:
+            old_checksum_props = self._metadata_store.retrieve(uid,
+                                                               ['checksum'])
+            old_checksum = old_checksum_props.get('checksum')
+            if old_checksum:
+                props['checksum'] = old_checksum
+
         self._metadata_store.store(uid, props)
         self._index_store.store(uid, props)
 
         if os.path.exists(self._file_store.get_file_path(uid)) and \
-                (not file_path or os.path.exists(file_path)):
+           os.path.exists(file_path):
             self._optimizer.remove(uid)
+
+        if not file_path and old_checksum:
+            # metadata-only update
+            self._update_completion_cb(async_cb, async_err_cb, uid,
+                                       need_optimizer_run=False)
+            return
+
         self._file_store.store(uid, file_path, transfer_ownership,
                 lambda * args: self._update_completion_cb(async_cb,
                                                          async_err_cb,
-- 
1.7.2.3



More information about the Sugar-devel mailing list