diff options
author | Zac Medico <zmedico@gentoo.org> | 2008-06-03 03:45:58 +0000 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2008-06-03 03:45:58 +0000 |
commit | 8c0755618fe67aa044c65f043c81b04d29f34db5 (patch) | |
tree | 8ed2dba0725d2cd9b0870ebb4a6bb45c11b3732a | |
parent | a3e771d1408e2ef8e20fc0f52a2c4f3618214f4a (diff) | |
download | portage-8c0755618fe67aa044c65f043c81b04d29f34db5.tar.gz portage-8c0755618fe67aa044c65f043c81b04d29f34db5.tar.bz2 portage-8c0755618fe67aa044c65f043c81b04d29f34db5.zip |
Fix vardbapi.flush_cache() so that it only updates the cache when the
number of uncached packages reaches a certain threshold (currently 5).
The cache file can be several megabytes in size, so updating it for
every vdb change is wasteful.
svn path=/main/trunk/; revision=10548
-rw-r--r-- | pym/portage/dbapi/vartree.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py index 5c15393fb..c2503eb42 100644 --- a/pym/portage/dbapi/vartree.py +++ b/pym/portage/dbapi/vartree.py @@ -238,6 +238,10 @@ class vardbapi(dbapi): _excluded_dirs = re.compile(r'^(\..*|-MERGING-.*|' + \ "|".join(_excluded_dirs) + r')$') + # Number of uncached packages to trigger cache update, since + # it's wasteful to update it for every vdb change. + _aux_cache_threshold = 5 + _aux_cache_keys_re = re.compile(r'^NEEDED\..*$') _aux_multi_line_re = re.compile(r'^(CONTENTS|NEEDED\..*)$') @@ -556,7 +560,7 @@ class vardbapi(dbapi): users have read access and benefit from faster metadata lookups (as long as at least part of the cache is still valid).""" if self._aux_cache is not None and \ - self._aux_cache["modified"] and \ + self._aux_cache["modified"] >= self._aux_cache_threshold and \ secpass >= 2: valid_nodes = set(self.cpv_all()) for cpv in self._aux_cache["packages"].keys(): @@ -571,7 +575,7 @@ class vardbapi(dbapi): self._aux_cache_filename, gid=portage_gid, mode=0644) except (IOError, OSError), e: pass - self._aux_cache["modified"] = False + self._aux_cache["modified"] = 0 def aux_get(self, mycpv, wants): """This automatically caches selected keys that are frequently needed @@ -616,7 +620,7 @@ class vardbapi(dbapi): not self._aux_cache.get("packages"): self._aux_cache = {"version": self._aux_cache_version} self._aux_cache["packages"] = {} - self._aux_cache["modified"] = False + self._aux_cache["modified"] = 0 mydir = self.getpath(mycpv) mydir_stat = None try: @@ -661,7 +665,7 @@ class vardbapi(dbapi): for aux_key in cache_these: cache_data[aux_key] = mydata[aux_key] self._aux_cache["packages"][mycpv] = (mydir_mtime, cache_data) - self._aux_cache["modified"] = True + self._aux_cache["modified"] += 1 return [mydata[x] for x in wants] def _aux_get(self, mycpv, wants): |