summaryrefslogtreecommitdiff
path: root/ishtar_common
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2019-05-28 13:08:58 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2019-06-17 13:21:28 +0200
commit907c4f5dafe3b2083ccb71ed1aacaf99bab63a59 (patch)
treefbb2677dbf1a24cec3b037d1d646d7b14e0dabfc /ishtar_common
parentc18ce7cf3939f7b9faaf8c4e2eb68df6b5fcabdf (diff)
downloadIshtar-907c4f5dafe3b2083ccb71ed1aacaf99bab63a59.tar.bz2
Ishtar-907c4f5dafe3b2083ccb71ed1aacaf99bab63a59.zip
Statistics cache: rpovide an expected type in order to fix bad cache init
Diffstat (limited to 'ishtar_common')
-rw-r--r--ishtar_common/models.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index 8d300c64a..bb19b0913 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -2945,19 +2945,28 @@ class DashboardFormItem(object):
"""
def _get_or_set_stats(self, funcname, update,
- timeout=settings.CACHE_TIMEOUT):
+ timeout=settings.CACHE_TIMEOUT,
+ expected_type=None):
model_name = self._meta.app_label + "." + self._meta.model_name
sc, __ = StatsCache.objects.get_or_create(
model=model_name, model_pk=self.pk
)
now = datetime.datetime.now()
- if sc.values and (
+ if not update and sc.values and (
sc.updated + datetime.timedelta(seconds=timeout)) > now:
values = sc.values
+ from_cache = True
else:
values = update_stats(sc, self, funcname)
+ from_cache = False
if "_raw_" in values:
- return values["_raw_"]
+ values = values["_raw_"]
+ if expected_type is not None and not isinstance(values, expected_type):
+ if from_cache:
+ return self._get_or_set_stats(funcname, True,
+ expected_type=expected_type)
+ else:
+ return expected_type()
return values
@classmethod