obscache: skip writing to disk if the data did not changed
authorPierre-Yves David <pierre-yves.david@ens-lyon.org>
Tue, 02 May 2017 17:43:34 +0200
changeset 2309 9f09cabe679e
parent 2308 ef8beb602b41
child 2311 26d638e419df
obscache: skip writing to disk if the data did not changed This will avoid rewriting the cache for every single transaction.
hgext3rd/evolve/obscache.py
--- a/hgext3rd/evolve/obscache.py	Tue May 02 16:19:05 2017 +0200
+++ b/hgext3rd/evolve/obscache.py	Tue May 02 17:43:34 2017 +0200
@@ -205,6 +205,7 @@
         # - obsstore-file-size (in bytes),
         # - obsstore "cache key"
         self._cachekey = None
+        self._ondiskkey = None
         self._data = bytearray()
 
     def get(self, rev):
@@ -302,7 +303,7 @@
         """save the data to disk"""
 
         # XXX it happens that the obsstore is (buggilly) always up to date on disk
-        if self._cachekey is None or self._cachekey == emptykey:
+        if self._cachekey is None or self._cachekey == self._ondiskkey:
             return
 
         with repo.vfs(self._filepath, 'w', atomictemp=True) as cachefile:
@@ -317,11 +318,12 @@
         data = repo.vfs.tryread(self._filepath)
         if not data:
             self._cachekey = emptykey
-            return
-
-        headersize = struct.calcsize(self._headerformat)
-        self._cachekey = struct.unpack(self._headerformat, data[:headersize])
-        self._data = bytearray(data[headersize:])
+            self._data = bytearray()
+        else:
+            headersize = struct.calcsize(self._headerformat)
+            self._cachekey = struct.unpack(self._headerformat, data[:headersize])
+            self._data = bytearray(data[headersize:])
+        self._ondiskkey = self._cachekey
 
 def _computeobsoleteset(orig, repo):
     """the set of obsolete revisions"""