From 77851f1d4b9ff318f16395047aaec1f464604dc5 Mon Sep 17 00:00:00 2001 From: Inso <insomniak.fr@gmail.com> Date: Fri, 17 Apr 2015 06:53:05 +0200 Subject: [PATCH] Fixed person caching --- src/cutecoin/core/person.py | 40 ++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/cutecoin/core/person.py b/src/cutecoin/core/person.py index 8d0c0bc5..ead30142 100644 --- a/src/cutecoin/core/person.py +++ b/src/cutecoin/core/person.py @@ -387,31 +387,31 @@ class Person(object): :return: True if a changed was made by the reload. ''' self._cache_mutex.lock() + change = False try: if community.currency not in self._cache: self._cache[community.currency] = {} - change = False - before = self._cache[community.currency][func.__name__] - - value = func(self, community) - - if not change: - if type(value) is dict: - hash_before = (hash(tuple(frozenset(sorted(before.keys())))), - hash(tuple(frozenset(sorted(before.items()))))) - hash_after = (hash(tuple(frozenset(sorted(value.keys())))), - hash(tuple(frozenset(sorted(value.items()))))) - change = hash_before != hash_after - elif type(value) is bool: - change = before != value - - self._cache[community.currency][func.__name__] = value + try: + before = self._cache[community.currency][func.__name__] + except KeyError: + change = True - except KeyError: - change = True - except Error: - return False + try: + value = func(self, community) + + if not change: + if type(value) is dict: + hash_before = (str(tuple(frozenset(sorted(before.keys())))), + str(tuple(frozenset(sorted(before.items()))))) + hash_after = (str(tuple(frozenset(sorted(value.keys())))), + str(tuple(frozenset(sorted(value.items()))))) + change = hash_before != hash_after + elif type(value) is bool: + change = before != value + self._cache[community.currency][func.__name__] = value + except Error: + return False finally: self._cache_mutex.unlock() return change -- GitLab