changeset 1476:581f72f9478b

maps: do not ask sqlite for min(rev), max(rev) together When min(rev) and max(rev) are being asked in a single sql query, sqlite is not smart enough to use the index and will iterate all rows. This patch splits the query so it could be answered instantly.
author Jun Wu <quark@fb.com>
date Thu, 23 Jun 2016 10:29:58 +0100
parents ea4d6142c6d9
children a4f77acf7051
files hgsubversion/maps.py
diffstat 1 files changed, 9 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/hgsubversion/maps.py
+++ b/hgsubversion/maps.py
@@ -567,13 +567,8 @@ class SqliteRevMap(collections.MutableMa
         self._db = None
         self._hashes = None
         self._opendb()
-        # update firstpulled, lastpulled
         self.firstpulled = 0
-        for row in self._query('SELECT MIN(rev), MAX(rev) FROM revmap'):
-            if row != (None, None):
-                self.firstpulled, lastpulled = row
-                if lastpulled > self.lastpulled:
-                    self.lastpulled = lastpulled
+        self._updatefirstlastpulled()
         # __iter__ is expensive and thus disabled by default
         # it should only be enabled for testing
         self._allowiter = False
@@ -748,6 +743,14 @@ class SqliteRevMap(collections.MutableMa
             f.write('%s\n' % self.VERSION)
             f.close()
 
+    def _updatefirstlastpulled(self):
+        sql = 'SELECT rev FROM revmap ORDER BY rev %s LIMIT 1'
+        for row in self._query(sql % 'ASC'):
+            self.firstpulled = row[0]
+        for row in self._query(sql % 'DESC'):
+            if row[0] > self.lastpulled:
+                self.lastpulled = row[0]
+
     @util.gcdisable
     def _importrevmapv1(self):
         with open(self._filepath, 'r') as f: