Gentoo Archives: gentoo-portage-dev

From: Zac Medico <zmedico@g.o>
To: gentoo-portage-dev@l.g.o, Brian Dolbec <dolsen@g.o>
Subject: Re: [gentoo-portage-dev] [PATCH] portdbapi.cp_list: cache repo associations (bug 650814)
Date: Sun, 15 Jul 2018 21:21:16
Message-Id: e5e6e049-77cd-9098-32ee-72ab25014b16@gentoo.org
In Reply to: Re: [gentoo-portage-dev] [PATCH] portdbapi.cp_list: cache repo associations (bug 650814) by Brian Dolbec
1 On 07/14/2018 09:42 PM, Brian Dolbec wrote:
2 > On Sat, 14 Jul 2018 21:05:39 -0700
3 > Zac Medico <zmedico@g.o> wrote:
4 >
5 >> Make portdbapi.cp_list return _pkg_str instances that have a 'repo'
6 >> attribute (bindbapi.cp_list already does this), with results
7 >> in ascending order by (pkg.version, repo.priority). Optimize
8 >> portdbapi.findname2 to use the 'repo' attribute to enable cached
9 >> results for files previously found by the portdbapi.cp_list
10 >> method, avoiding filesystem access when possible. Optimize the
11 >> depgraph._iter_match_pkgs_atom method by elimination of the repo
12 >> loop, since portdbapi.cp_list now returns separate items when the
13 >> same package version is found in multiple repos.
14 >>
15 >> Bug: https://bugs.gentoo.org/650814
16 >> ---
17 >> pym/_emerge/depgraph.py | 12 +++---------
18 >> pym/portage/dbapi/porttree.py | 41
19 >> +++++++++++++++++++++++++++++------------ 2 files changed, 32
20 >> insertions(+), 21 deletions(-)
21 >>
22 >> diff --git a/pym/_emerge/depgraph.py b/pym/_emerge/depgraph.py
23 >> index 42857c1a5..b63d4f242 100644
24 >> --- a/pym/_emerge/depgraph.py
25 >> +++ b/pym/_emerge/depgraph.py
26 >> @@ -5613,10 +5613,6 @@ class depgraph(object):
27 >> if cp_list:
28 >> atom_set =
29 >> InternalPackageSet(initial_atoms=(atom,), allow_repo=True)
30 >> - if atom.repo is None and hasattr(db,
31 >> "getRepositories"):
32 >> - repo_list =
33 >> db.getRepositories(catpkg=atom_exp.cp)
34 >> - else:
35 >> - repo_list = [atom.repo]
36 >>
37 >> # descending order
38 >> cp_list.reverse()
39 >> @@ -5624,13 +5620,11 @@ class depgraph(object):
40 >> # Call match_from_list on one cpv at
41 >> a time, in order # to avoid unnecessary match_from_list comparisons on
42 >> # versions that are never yielded
43 >> from this method.
44 >> - if not match_from_list(atom_exp,
45 >> [cpv]):
46 >> - continue
47 >> - for repo in repo_list:
48 >> -
49 >> + if match_from_list(atom_exp, [cpv]):
50 >> try:
51 >> pkg = self._pkg(cpv,
52 >> pkg_type, root_config,
53 >> -
54 >> installed=installed, onlydeps=onlydeps, myrepo=repo)
55 >> +
56 >> installed=installed, onlydeps=onlydeps,
57 >> +
58 >> myrepo=getattr(cpv, 'repo', None)) except
59 >> portage.exception.PackageNotFound: pass
60 >> else:
61 >> diff --git a/pym/portage/dbapi/porttree.py
62 >> b/pym/portage/dbapi/porttree.py index 3e36024ff..f6076ee2b 100644
63 >> --- a/pym/portage/dbapi/porttree.py
64 >> +++ b/pym/portage/dbapi/porttree.py
65 >> @@ -459,6 +459,9 @@ class portdbapi(dbapi):
66 >> mytree = self.treemap.get(myrepo)
67 >> if mytree is None:
68 >> return (None, 0)
69 >> + elif mytree is not None:
70 >> + # myrepo enables cached results when
71 >> available
72 >> + myrepo =
73 >> self.repositories.location_map.get(mytree)
74 >> mysplit = mycpv.split("/")
75 >> psplit = pkgsplit(mysplit[1])
76 >> @@ -495,6 +498,14 @@ class portdbapi(dbapi):
77 >> relative_path = mysplit[0] + _os.sep + psplit[0] +
78 >> _os.sep + \ mysplit[1] + ".ebuild"
79 >>
80 >> + # There is no need to access the filesystem when the
81 >> package
82 >> + # comes from this db and the package repo attribute
83 >> corresponds
84 >> + # to the desired repo, since the file was previously
85 >> found by
86 >> + # the cp_list method.
87 >> + if (myrepo is not None and myrepo == getattr(mycpv,
88 >> 'repo', None)
89 >> + and self is getattr(mycpv, '_db', None)):
90 >> + return (mytree + _os.sep + relative_path,
91 >> mytree) +
92 >> for x in mytrees:
93 >> filename = x + _os.sep + relative_path
94 >> if _os.access(_unicode_encode(filename,
95 >> @@ -950,18 +961,23 @@ class portdbapi(dbapi):
96 >> return cachelist[:]
97 >> mysplit = mycp.split("/")
98 >> invalid_category = mysplit[0] not in self._categories
99 >> - d={}
100 >> + # Process repos in ascending order by repo.priority,
101 >> so that
102 >> + # stable sort by version produces results ordered by
103 >> + # (pkg.version, repo.priority).
104 >> if mytree is not None:
105 >> if isinstance(mytree, basestring):
106 >> - mytrees = [mytree]
107 >> + repos =
108 >> [self.repositories.get_repo_for_location(mytree)] else:
109 >> # assume it's iterable
110 >> - mytrees = mytree
111 >> + repos =
112 >> [self.repositories.get_repo_for_location(location)
113 >> + for location in mytree]
114 >> elif self._better_cache is None:
115 >> - mytrees = self.porttrees
116 >> + repos = list(self.repositories)
117 >> else:
118 >> - mytrees = [repo.location for repo in
119 >> self._better_cache[mycp]]
120 >> - for oroot in mytrees:
121 >> + repos = reversed(self._better_cache[mycp])
122 >> + mylist = []
123 >> + for repo in repos:
124 >> + oroot = repo.location
125 >> try:
126 >> file_list =
127 >> os.listdir(os.path.join(oroot, mycp)) except OSError:
128 >> @@ -986,16 +1002,17 @@ class portdbapi(dbapi):
129 >> writemsg(_("\nInvalid
130 >> ebuild version: %s\n") % \ os.path.join(oroot, mycp, x),
131 >> noiselevel=-1) continue
132 >> -
133 >> d[_pkg_str(mysplit[0]+"/"+pf, db=self)] = None
134 >> - if invalid_category and d:
135 >> +
136 >> mylist.append(_pkg_str(mysplit[0]+"/"+pf, db=self, repo=repo.name))
137 >> + if invalid_category and mylist:
138 >> writemsg(_("\n!!! '%s' has a category that
139 >> is not listed in " \ "%setc/portage/categories\n") % \
140 >> (mycp,
141 >> self.settings["PORTAGE_CONFIGROOT"]), noiselevel=-1) mylist = []
142 >> - else:
143 >> - mylist = list(d)
144 >> - # Always sort in ascending order here since it's
145 >> handy
146 >> - # and the result can be easily cached and reused.
147 >> + # Always sort in ascending order here since it's
148 >> handy and
149 >> + # the result can be easily cached and reused. Since
150 >> mylist
151 >> + # is initially in ascending order by repo.priority,
152 >> stable
153 >> + # sort by version produces results in ascending
154 >> order by
155 >> + # (pkg.version, repo.priority).
156 >> self._cpv_sort_ascending(mylist)
157 >> if self.frozen and mytree is None:
158 >> cachelist = mylist[:]
159 >
160 > looks fine
161
162 Thanks, merged:
163
164 https://gitweb.gentoo.org/proj/portage.git/commit/?id=27eeeb6e4fc8e68efa003b2db5bbd8cc4afe336a
165
166 --
167 Thanks,
168 Zac

Attachments

File name MIME type
signature.asc application/pgp-signature