Gentoo Archives: gentoo-portage-dev

From: Sebastian Luther <SebastianLuther@×××.de>
To: gentoo-portage-dev@l.g.o
Subject: Re: [gentoo-portage-dev] [PATCH] portdbapi: Add cache to avoid repeated failing os.access calls
Date: Wed, 19 Feb 2014 19:01:28
Message-Id: 5304FF82.8000305@gmx.de
In Reply to: Re: [gentoo-portage-dev] [PATCH] portdbapi: Add cache to avoid repeated failing os.access calls by David James
1 Am 18.02.2014 22:35, schrieb David James:
2 > """
3 > + cache_key = (mycpv, mytree, myrepo)
4 > + try:
5 > + return self._findname2_cache[cache_key]
6 > + except KeyError:
7 > + self._findname2_cache[cache_key] = (None, 0)
8 >
9 >
10 > To me, it seems potentially error-prone to cache a (potentially)
11 > incorrect value and then correct it later.
12
13 It is. The problem are all these returns. The whole thing would need to
14 be reorganized to fix this. I'd rather go for a memoize decorator and
15 leave that thing alone. If I just could find a usable one.
16
17 Would it be possible to
18 > refactor your patch so that we only cache the value when we know the
19 > final answer?
20 >
21 >
22 > + except TypeError:
23 >
24 >
25 > In what circumstances does it happen that mytree / myrepo are unhashable
26 > types? Can you add a comment to explain this?
27
28 That's my mistake. I was under the impression that mytree is actually
29 mytreeS and would accept a list. I'll remove the "except TypeError:" in
30 a future version of the patch.