Skip to content
Snippets Groups Projects
Commit 77851f1d authored by inso's avatar inso
Browse files

Fixed person caching

parent 8eb586da
No related branches found
No related tags found
No related merge requests found
...@@ -387,31 +387,31 @@ class Person(object): ...@@ -387,31 +387,31 @@ class Person(object):
:return: True if a changed was made by the reload. :return: True if a changed was made by the reload.
''' '''
self._cache_mutex.lock() self._cache_mutex.lock()
change = False
try: try:
if community.currency not in self._cache: if community.currency not in self._cache:
self._cache[community.currency] = {} self._cache[community.currency] = {}
change = False try:
before = self._cache[community.currency][func.__name__] before = self._cache[community.currency][func.__name__]
except KeyError:
value = func(self, community) change = True
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
except KeyError: try:
change = True value = func(self, community)
except Error:
return False 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: finally:
self._cache_mutex.unlock() self._cache_mutex.unlock()
return change return change
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment