comparison hgsubversion/maps.py @ 1478:797c7b58a735

maps: add a config option to tweak sqlite Sqlite is highly configurable by PRAGMA statements [1]. This patch adds a config option to give the user changes to tweak them. [1]: https://www.sqlite.org/pragma.html
author Jun Wu <quark@fb.com>
date Thu, 23 Jun 2016 20:03:30 +0100
parents a4f77acf7051
children bc73b80baf98
comparison
equal deleted inserted replaced
1477:a4f77acf7051 1478:797c7b58a735
556 lastpulled = util.fileproperty('_lastpulled', lambda x: x._lastpulledpath, 556 lastpulled = util.fileproperty('_lastpulled', lambda x: x._lastpulledpath,
557 default=0, deserializer=int) 557 default=0, deserializer=int)
558 rowcount = util.fileproperty('_rowcount', lambda x: x._rowcountpath, 558 rowcount = util.fileproperty('_rowcount', lambda x: x._rowcountpath,
559 default=0, deserializer=int) 559 default=0, deserializer=int)
560 560
561 def __init__(self, revmap_path, lastpulled_path): 561 def __init__(self, revmap_path, lastpulled_path, sqlitepragmas=None):
562 self._filepath = revmap_path 562 self._filepath = revmap_path
563 self._dbpath = revmap_path + '.db' 563 self._dbpath = revmap_path + '.db'
564 self._rowcountpath = self._dbpath + '.rowcount' 564 self._rowcountpath = self._dbpath + '.rowcount'
565 self._lastpulledpath = lastpulled_path 565 self._lastpulledpath = lastpulled_path
566 566
567 self._db = None 567 self._db = None
568 self._hashes = None 568 self._hashes = None
569 self._sqlitepragmas = sqlitepragmas
569 self.firstpulled = 0 570 self.firstpulled = 0
570 self._updatefirstlastpulled() 571 self._updatefirstlastpulled()
571 # __iter__ is expensive and thus disabled by default 572 # __iter__ is expensive and thus disabled by default
572 # it should only be enabled for testing 573 # it should only be enabled for testing
573 self._allowiter = False 574 self._allowiter = False
717 cachesize = 2000 718 cachesize = 2000
718 for path, ratio in [(self._filepath, 1.7), (self._dbpath, 1)]: 719 for path, ratio in [(self._filepath, 1.7), (self._dbpath, 1)]:
719 if os.path.exists(path): 720 if os.path.exists(path):
720 cachesize += os.stat(path).st_size * ratio // 1000 721 cachesize += os.stat(path).st_size * ratio // 1000
721 self._db.execute('PRAGMA cache_size=%d' % (-cachesize)) 722 self._db.execute('PRAGMA cache_size=%d' % (-cachesize))
723
724 # PRAGMA statements provided by the user
725 for pragma in (self._sqlitepragmas or []):
726 # drop malicious ones
727 if re.match(r'\A\w+=\w+\Z', pragma):
728 self._db.execute('PRAGMA %s' % pragma)
722 729
723 # disable auto-commit. everything is inside a transaction 730 # disable auto-commit. everything is inside a transaction
724 self._db.isolation_level = 'DEFERRED' 731 self._db.isolation_level = 'DEFERRED'
725 732
726 with self._transaction('EXCLUSIVE'): 733 with self._transaction('EXCLUSIVE'):