dbapi.cp_list: remove special case for virtuals
authorZac Medico <zmedico@gentoo.org>
Sun, 22 Apr 2012 18:57:25 +0000 (11:57 -0700)
committerZac Medico <zmedico@gentoo.org>
Sun, 22 Apr 2012 18:57:25 +0000 (11:57 -0700)
Since commit d603f1440c814377fbc1965729fd9b6b008cf76d, the match caches
use the result from dep_expand for the cache_key, so the caches are
free of old-style virtual mappings. This allows the match caches to be
safely shared with cp_list.

pym/_emerge/PackageVirtualDbapi.py
pym/portage/dbapi/porttree.py
pym/portage/dbapi/virtual.py

index a34d21c83269d743435193ed4179af3d561c6732..0f7be44b1c69daabc383a90a027c80b323c0de25 100644 (file)
@@ -90,10 +90,11 @@ class PackageVirtualDbapi(dbapi):
                return cpv in self._cpv_map
 
        def cp_list(self, mycp, use_cache=1):
+               # NOTE: Cache can be safely shared with the match cache, since the
+               # match cache uses the result from dep_expand for the cache_key.
                cache_key = (mycp, mycp)
                cachelist = self._match_cache.get(cache_key)
-               # cp_list() doesn't expand old-style virtuals
-               if cachelist and cachelist[0].startswith(mycp):
+               if cachelist is not None:
                        return cachelist[:]
                cpv_list = self._cp_map.get(mycp)
                if cpv_list is None:
@@ -101,8 +102,7 @@ class PackageVirtualDbapi(dbapi):
                else:
                        cpv_list = [pkg.cpv for pkg in cpv_list]
                self._cpv_sort_ascending(cpv_list)
-               if not (not cpv_list and mycp.startswith("virtual/")):
-                       self._match_cache[cache_key] = cpv_list
+               self._match_cache[cache_key] = cpv_list
                return cpv_list[:]
 
        def cp_all(self):
index f9d78dcdbc21870844218cab36b869b1f3c0687b..b060dd6a50af31e524041f548872887860218168 100644 (file)
@@ -715,7 +715,8 @@ class portdbapi(dbapi):
                return l
 
        def cp_list(self, mycp, use_cache=1, mytree=None):
-
+               # NOTE: Cache can be safely shared with the match cache, since the
+               # match cache uses the result from dep_expand for the cache_key.
                if self.frozen and mytree is not None \
                        and len(self.porttrees) == 1 \
                        and mytree == self.porttrees[0]:
@@ -728,10 +729,8 @@ class portdbapi(dbapi):
                        if cachelist is not None:
                                # Try to propagate this to the match-all cache here for
                                # repoman since he uses separate match-all caches for each
-                               # profile (due to old-style virtuals). Do not propagate
-                               # old-style virtuals since cp_list() doesn't expand them.
-                               if not (not cachelist and mycp.startswith("virtual/")):
-                                       self.xcache["match-all"][(mycp, mycp)] = cachelist
+                               # profile (due to old-style virtuals).
+                               self.xcache["match-all"][(mycp, mycp)] = cachelist
                                return cachelist[:]
                mysplit = mycp.split("/")
                invalid_category = mysplit[0] not in self._categories
@@ -783,10 +782,7 @@ class portdbapi(dbapi):
                if self.frozen and mytree is None:
                        cachelist = mylist[:]
                        self.xcache["cp-list"][mycp] = cachelist
-                       # Do not propagate old-style virtuals since
-                       # cp_list() doesn't expand them.
-                       if not (not cachelist and mycp.startswith("virtual/")):
-                               self.xcache["match-all"][(mycp, mycp)] = cachelist
+                       self.xcache["match-all"][(mycp, mycp)] = cachelist
                return mylist
 
        def freeze(self):
index eed1407fc0ee60c7dd87ad1c2e19c97930ab9778..8a35d0ce90851c2d1cb4ad4470770bda8ef46054 100644 (file)
@@ -45,6 +45,8 @@ class fakedbapi(dbapi):
                return mycpv in self.cpvdict
 
        def cp_list(self, mycp, use_cache=1, myrepo=None):
+               # NOTE: Cache can be safely shared with the match cache, since the
+               # match cache uses the result from dep_expand for the cache_key.
                cache_key = (mycp, mycp)
                cachelist = self._match_cache.get(cache_key)
                # cp_list() doesn't expand old-style virtuals
@@ -54,8 +56,7 @@ class fakedbapi(dbapi):
                if cpv_list is None:
                        cpv_list = []
                self._cpv_sort_ascending(cpv_list)
-               if not (not cpv_list and mycp.startswith("virtual/")):
-                       self._match_cache[cache_key] = cpv_list
+               self._match_cache[cache_key] = cpv_list
                return cpv_list[:]
 
        def cp_all(self):