From: Zac Medico Date: Tue, 3 Jun 2008 04:04:14 +0000 (-0000) Subject: Add modification threshold for BlockerCache.flush(), to avoid wasteful IO. X-Git-Tag: v2.2_pre8~38 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=e73b7aab1e9c07e95a2d4d3206f74897e0caa363;p=portage.git Add modification threshold for BlockerCache.flush(), to avoid wasteful IO. svn path=/main/trunk/; revision=10549 --- diff --git a/pym/_emerge/__init__.py b/pym/_emerge/__init__.py index f346093ed..ae471a975 100644 --- a/pym/_emerge/__init__.py +++ b/pym/_emerge/__init__.py @@ -1449,6 +1449,11 @@ class BlockerCache(DictMixin): 1) the set of installed packages (including COUNTER) has changed 2) the old-style virtuals have changed """ + + # Number of uncached packages to trigger cache update, since + # it's wasteful to update it for every vdb change. + _cache_threshold = 5 + class BlockerData(object): __slots__ = ("__weakref__", "atoms", "counter") @@ -1464,7 +1469,7 @@ class BlockerCache(DictMixin): portage.CACHE_PATH.lstrip(os.path.sep), "vdb_blockers.pickle") self._cache_version = "1" self._cache_data = None - self._modified = False + self._modified = 0 self._load() def _load(self): @@ -1534,7 +1539,7 @@ class BlockerCache(DictMixin): self._cache_data = {"version":self._cache_version} self._cache_data["blockers"] = {} self._cache_data["virtuals"] = self._virtuals - self._modified = False + self._modified = 0 def flush(self): """If the current user has permission and the internal blocker cache @@ -1552,7 +1557,7 @@ class BlockerCache(DictMixin): "virtuals" : vardb.settings.getvirtuals() } """ - if self._modified and \ + if self._modified >= self._cache_threshold and \ secpass >= 2: try: f = portage.util.atomic_ofstream(self._cache_filename) @@ -1562,7 +1567,7 @@ class BlockerCache(DictMixin): self._cache_filename, gid=portage.portage_gid, mode=0644) except (IOError, OSError), e: pass - self._modified = False + self._modified = 0 def __setitem__(self, cpv, blocker_data): """ @@ -1576,14 +1581,13 @@ class BlockerCache(DictMixin): """ self._cache_data["blockers"][cpv] = \ (blocker_data.counter, tuple(str(x) for x in blocker_data.atoms)) - self._modified = True + self._modified += 1 def __iter__(self): return iter(self._cache_data["blockers"]) def __delitem__(self, cpv): del self._cache_data["blockers"][cpv] - self._modified = True def __getitem__(self, cpv): """