Gentoo Archives: gentoo-portage-dev

From: Sebastian Luther <SebastianLuther@×××.de>
To: gentoo-portage-dev@l.g.o
Subject: [gentoo-portage-dev] [PATCH] portdbapi: Add cache to avoid repeated failing os.access calls
Date: Tue, 18 Feb 2014 21:02:39
Message-Id: 1392757337-26882-2-git-send-email-SebastianLuther@gmx.de
In Reply to: [gentoo-portage-dev] Avoid repeated failing os.access by Sebastian Luther
1 ---
2 pym/portage/dbapi/porttree.py | 13 +++++++++++++
3 1 file changed, 13 insertions(+)
4
5 diff --git a/pym/portage/dbapi/porttree.py b/pym/portage/dbapi/porttree.py
6 index 590e3c5..2dc406b 100644
7 --- a/pym/portage/dbapi/porttree.py
8 +++ b/pym/portage/dbapi/porttree.py
9 @@ -254,6 +254,7 @@ class portdbapi(dbapi):
10
11 self._aux_cache = {}
12 self._broken_ebuilds = set()
13 + self._findname2_cache = {}
14
15 @property
16 def _event_loop(self):
17 @@ -372,6 +373,14 @@ class portdbapi(dbapi):
18 the file we wanted.
19 If myrepo is not None it will find packages from this repository(overlay)
20 """
21 + cache_key = (mycpv, mytree, myrepo)
22 + try:
23 + return self._findname2_cache[cache_key]
24 + except KeyError:
25 + self._findname2_cache[cache_key] = (None, 0)
26 + except TypeError:
27 + cache_key = None
28 +
29 if not mycpv:
30 return (None, 0)
31
32 @@ -383,6 +392,8 @@ class portdbapi(dbapi):
33 mysplit = mycpv.split("/")
34 psplit = pkgsplit(mysplit[1])
35 if psplit is None or len(mysplit) != 2:
36 + if cache_key:
37 + del self._findname2_cache[cache_key]
38 raise InvalidPackageName(mycpv)
39
40 # For optimal performace in this hot spot, we do manual unicode
41 @@ -402,6 +413,8 @@ class portdbapi(dbapi):
42 filename = x + _os.sep + relative_path
43 if _os.access(_unicode_encode(filename,
44 encoding=encoding, errors=errors), _os.R_OK):
45 + if cache_key:
46 + self._findname2_cache[cache_key] = (filename, x)
47 return (filename, x)
48 return (None, 0)
49
50 --
51 1.8.3.2

Replies