Use sets for more accurate cache modification counts BlockerCache and vardbapi.
authorZac Medico <zmedico@gentoo.org>
Wed, 4 Jun 2008 20:24:31 +0000 (20:24 -0000)
committerZac Medico <zmedico@gentoo.org>
Wed, 4 Jun 2008 20:24:31 +0000 (20:24 -0000)
svn path=/main/trunk/; revision=10578

pym/_emerge/__init__.py
pym/portage/dbapi/vartree.py

index 7fd1373ad050ce2cd6dda5a8a86ec88d37011f87..12723e6552bfe93fe53ec941cf5968db8be933bf 100644 (file)
@@ -1470,7 +1470,7 @@ class BlockerCache(DictMixin):
                        portage.CACHE_PATH.lstrip(os.path.sep), "vdb_blockers.pickle")
                self._cache_version = "1"
                self._cache_data = None
-               self._modified = 0
+               self._modified = set()
                self._load()
 
        def _load(self):
@@ -1540,7 +1540,7 @@ class BlockerCache(DictMixin):
                        self._cache_data = {"version":self._cache_version}
                        self._cache_data["blockers"] = {}
                        self._cache_data["virtuals"] = self._virtuals
-               self._modified = 0
+               self._modified.clear()
 
        def flush(self):
                """If the current user has permission and the internal blocker cache
@@ -1558,7 +1558,7 @@ class BlockerCache(DictMixin):
                        "virtuals" : vardb.settings.getvirtuals()
                }
                """
-               if self._modified >= self._cache_threshold and \
+               if len(self._modified) >= self._cache_threshold and \
                        secpass >= 2:
                        try:
                                f = portage.util.atomic_ofstream(self._cache_filename)
@@ -1568,7 +1568,7 @@ class BlockerCache(DictMixin):
                                        self._cache_filename, gid=portage.portage_gid, mode=0644)
                        except (IOError, OSError), e:
                                pass
-                       self._modified = 0
+                       self._modified.clear()
 
        def __setitem__(self, cpv, blocker_data):
                """
@@ -1582,7 +1582,7 @@ class BlockerCache(DictMixin):
                """
                self._cache_data["blockers"][cpv] = \
                        (blocker_data.counter, tuple(str(x) for x in blocker_data.atoms))
-               self._modified += 1
+               self._modified.add(cpv)
 
        def __iter__(self):
                return iter(self._cache_data["blockers"])
index 48cd0c731debe90dd7edc1dd1189ce2718b04f4c..d931c5ddf22d1c84272bbb96be03b121299787cd 100644 (file)
@@ -560,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"] >= self._aux_cache_threshold and \
+                       len(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():
@@ -575,7 +575,7 @@ class vardbapi(dbapi):
                                        self._aux_cache_filename, gid=portage_gid, mode=0644)
                        except (IOError, OSError), e:
                                pass
-                       self._aux_cache["modified"] = 0
+                       self._aux_cache["modified"] = set()
 
        def aux_get(self, mycpv, wants):
                """This automatically caches selected keys that are frequently needed
@@ -620,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"] = 0
+                       self._aux_cache["modified"] = set()
                mydir = self.getpath(mycpv)
                mydir_stat = None
                try:
@@ -665,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"] += 1
+                               self._aux_cache["modified"].add(mycpv)
                return [mydata[x] for x in wants]
 
        def _aux_get(self, mycpv, wants):