diff options
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 |