diff options
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 |
commit | 9f53334ba76bbe2a93b68607181acfa51e2e544c (patch) | |
tree | fbb2677dbf1a24cec3b037d1d646d7b14e0dabfc /ishtar_common/models.py | |
parent | 7c217d2580ff9decf7563f675c8d822c70d9f397 (diff) | |
download | Ishtar-9f53334ba76bbe2a93b68607181acfa51e2e544c.tar.bz2 Ishtar-9f53334ba76bbe2a93b68607181acfa51e2e544c.zip |
Statistics cache: rpovide an expected type in order to fix bad cache init
Diffstat (limited to 'ishtar_common/models.py')
-rw-r--r-- | ishtar_common/models.py | 15 |
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 |