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