1 |
On Tue, Feb 18, 2014 at 1:02 PM, Sebastian Luther <SebastianLuther@×××.de>wrote: |
2 |
|
3 |
> --- |
4 |
> pym/portage/dbapi/porttree.py | 13 +++++++++++++ |
5 |
> 1 file changed, 13 insertions(+) |
6 |
> |
7 |
> diff --git a/pym/portage/dbapi/porttree.py b/pym/portage/dbapi/porttree.py |
8 |
> index 590e3c5..2dc406b 100644 |
9 |
> --- a/pym/portage/dbapi/porttree.py |
10 |
> +++ b/pym/portage/dbapi/porttree.py |
11 |
> @@ -254,6 +254,7 @@ class portdbapi(dbapi): |
12 |
> |
13 |
> self._aux_cache = {} |
14 |
> self._broken_ebuilds = set() |
15 |
> + self._findname2_cache = {} |
16 |
> |
17 |
> @property |
18 |
> def _event_loop(self): |
19 |
> @@ -372,6 +373,14 @@ class portdbapi(dbapi): |
20 |
> the file we wanted. |
21 |
> If myrepo is not None it will find packages from this |
22 |
> repository(overlay) |
23 |
> """ |
24 |
> + cache_key = (mycpv, mytree, myrepo) |
25 |
> + try: |
26 |
> + return self._findname2_cache[cache_key] |
27 |
> + except KeyError: |
28 |
> + self._findname2_cache[cache_key] = (None, 0) |
29 |
> |
30 |
|
31 |
To me, it seems potentially error-prone to cache a (potentially) incorrect |
32 |
value and then correct it later. Would it be possible to refactor your |
33 |
patch so that we only cache the value when we know the final answer? |
34 |
|
35 |
|
36 |
> + except TypeError: |
37 |
> |
38 |
|
39 |
In what circumstances does it happen that mytree / myrepo are unhashable |
40 |
types? Can you add a comment to explain this? |
41 |
|
42 |
+ cache_key = None |
43 |
> + |
44 |
> if not mycpv: |
45 |
> return (None, 0) |
46 |
> |
47 |
> @@ -383,6 +392,8 @@ class portdbapi(dbapi): |
48 |
> mysplit = mycpv.split("/") |
49 |
> psplit = pkgsplit(mysplit[1]) |
50 |
> if psplit is None or len(mysplit) != 2: |
51 |
> + if cache_key: |
52 |
> + del self._findname2_cache[cache_key] |
53 |
|
54 |
raise InvalidPackageName(mycpv) |
55 |
> |
56 |
> # For optimal performace in this hot spot, we do manual |
57 |
> unicode |
58 |
> @@ -402,6 +413,8 @@ class portdbapi(dbapi): |
59 |
> filename = x + _os.sep + relative_path |
60 |
> if _os.access(_unicode_encode(filename, |
61 |
> encoding=encoding, errors=errors), |
62 |
> _os.R_OK): |
63 |
> + if cache_key: |
64 |
> + self._findname2_cache[cache_key] = |
65 |
> (filename, x) |
66 |
> return (filename, x) |
67 |
> return (None, 0) |
68 |
> |
69 |
> -- |
70 |
> 1.8.3.2 |
71 |
> |
72 |
> |
73 |
> |