From 97d2dac2cb7ee7ad33a31786eed74e1c204576dd Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Sat, 24 Sep 2011 13:14:59 -0700 Subject: portdbapi: tweak single-tree optimization This optimizes aux_get and cp_list for cases where we only have a single tree, which is common for repoman and ebuild(1). --- pym/portage/dbapi/porttree.py | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/pym/portage/dbapi/porttree.py b/pym/portage/dbapi/porttree.py index d3cca00f5..42e5ca168 100644 --- a/pym/portage/dbapi/porttree.py +++ b/pym/portage/dbapi/porttree.py @@ -465,9 +465,16 @@ class portdbapi(dbapi): if mytree is None: raise KeyError(myrepo) - if not mytree: + if mytree is not None and len(self.porttrees) == 1 \ + and mytree == self.porttrees[0]: + # mytree matches our only tree, so it's safe to + # ignore mytree and cache the result + mytree = None + myrepo = None + + if mytree is None: cache_me = True - if not mytree and not self._known_keys.intersection( + if mytree is None and not self._known_keys.intersection( mylist).difference(self._aux_cache_keys): aux_cache = self._aux_cache.get(mycpv) if aux_cache is not None: @@ -730,6 +737,14 @@ class portdbapi(dbapi): return l def cp_list(self, mycp, use_cache=1, mytree=None): + + if self.frozen and mytree is not None \ + and len(self.porttrees) == 1 \ + and mytree == self.porttrees[0]: + # mytree matches our only tree, so it's safe to + # ignore mytree and cache the result + mytree = None + if self.frozen and mytree is None: cachelist = self.xcache["cp-list"].get(mycp) if cachelist is not None: @@ -857,7 +872,7 @@ class portdbapi(dbapi): # match *all* visible *and* masked packages if mydep == mykey: myval = self.cp_list(mykey, mytree=mytree) - elif mydep.repo is not None or len(self.porttrees) == 1: + elif mydep.repo is not None: myval = list(self._iter_match(mydep, self.cp_list(mykey, mytree=mytree))) else: @@ -886,7 +901,7 @@ class portdbapi(dbapi): if mydep == mykey: for myval in self.cp_list(mykey, mytree=mytree): break - elif mydep.repo is not None or len(self.porttrees) == 1: + elif mydep.repo is not None: for myval in self._iter_match(mydep, self.cp_list(mykey, mytree=mytree)): break @@ -917,7 +932,7 @@ class portdbapi(dbapi): else: iterfunc = reversed - if mydep.repo is not None or len(self.porttrees) == 1: + if mydep.repo is not None: repos = [mydep.repo] else: # We iterate over self.porttrees, since it's common to @@ -1010,9 +1025,7 @@ class portdbapi(dbapi): aux_keys = list(self._aux_cache_keys) metadata = {} - if len(self.porttrees) == 1: - repos = [None] - elif myrepo is not None: + if myrepo is not None: repos = [myrepo] else: # We iterate over self.porttrees, since it's common to -- cgit v1.2.3-1-g7c22