summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2008-06-03 04:04:14 +0000
committerZac Medico <zmedico@gentoo.org>2008-06-03 04:04:14 +0000
commite73b7aab1e9c07e95a2d4d3206f74897e0caa363 (patch)
tree8afc0626230a9af3ea9c083509b7d185f663351c
parent8c0755618fe67aa044c65f043c81b04d29f34db5 (diff)
downloadportage-e73b7aab1e9c07e95a2d4d3206f74897e0caa363.tar.gz
portage-e73b7aab1e9c07e95a2d4d3206f74897e0caa363.tar.bz2
portage-e73b7aab1e9c07e95a2d4d3206f74897e0caa363.zip
Add modification threshold for BlockerCache.flush(), to avoid wasteful IO.
svn path=/main/trunk/; revision=10549
-rw-r--r--pym/_emerge/__init__.py16
1 files changed, 10 insertions, 6 deletions
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):
"""