# HG changeset patch # User Pierre-Yves David # Date 1534443739 -7200 # Node ID 2174de498a69e2fe92112e9f1bcde75d80806452 # Parent a7794f5abacdc1824c47552ec27ef835a7cf65aa stablerange: build closure a bit less inefficiently The new way make me a bit less sad than the old one. diff -r a7794f5abacd -r 2174de498a69 hgext3rd/evolve/stablerangecache.py --- a/hgext3rd/evolve/stablerangecache.py Thu Aug 16 22:19:19 2018 +0200 +++ b/hgext3rd/evolve/stablerangecache.py Thu Aug 16 20:22:19 2018 +0200 @@ -9,6 +9,7 @@ import abc import heapq +import random import sqlite3 import time import weakref @@ -119,10 +120,17 @@ FROM subranges WHERE (suprev = ? AND supidx = ?) ORDER BY listidx;""" -_querysuperranges = """SELECT suprev, supidx - FROM subranges - WHERE (subrev = ? AND subidx = ?) - ORDER BY listidx;""" + +_querysuperrangesmain = """SELECT DISTINCT suprev, supidx + FROM subranges + WHERE %s;""" + +_querysuperrangesbody = '(subrev = %d and subidx = %d)' + +def _make_querysuperranges(ranges): + # building a tree of OR would allow for more ranges + body = ' OR '.join(_querysuperrangesbody % r for r in ranges) + return _querysuperrangesmain % body class stablerangesqlbase(stablerange.stablerangecached): """class that can handle all the bits needed to store range into sql @@ -151,10 +159,14 @@ new.add((r, 0)) con = self._con while new and con is not None: - # many execute is not efficient - next = new.pop() - known.add(next) - ranges = set(con.execute(_querysuperranges, next).fetchall()) + new + if len(new) < 300: + sample = new + else: + sample = random.sample(new, 300) + known.update(sample) + query = _make_querysuperranges(sample) + ranges = set(con.execute(query).fetchall()) new.update(ranges) new -= known return sorted(known)