# HG changeset patch # User Jun Wu # Date 1466674198 -3600 # Node ID 581f72f9478b852808abe2978b7500dc750f0e87 # Parent ea4d6142c6d9cd07b591f371f779285d3002a7c3 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. diff --git a/hgsubversion/maps.py b/hgsubversion/maps.py --- 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: