summaryrefslogtreecommitdiff
path: root/ishtar_common/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar_common/models.py')
-rw-r--r--ishtar_common/models.py31
1 files changed, 16 insertions, 15 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index 2d3320e2e..6eea042ce 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -3403,33 +3403,34 @@ class DashboardFormItem(object):
Provide methods to manage statistics
"""
- def _get_or_set_stats(self, funcname, update,
- timeout=settings.CACHE_TIMEOUT,
+ def last_stats_update(self):
+ model_name = self._meta.app_label + "." + self._meta.model_name
+ q = StatsCache.objects.filter(
+ model=model_name, model_pk=self.pk).order_by("-updated")
+ if not q.count():
+ return
+ return q.all()[0].updated
+
+ def _get_or_set_stats(self, funcname, update=False,
expected_type=None):
- values = {}
- from_cache = False
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 not settings.DEBUG and (
- not update and sc.values and funcname in sc.values and (
- sc.updated + datetime.timedelta(seconds=timeout)) > now):
+ if not update:
values = sc.values
- from_cache = True
- if funcname not in values:
+ if funcname not in values:
+ if expected_type is not None:
+ return expected_type()
+ return 0
+ else:
values = update_stats(sc, self, funcname)
if funcname in values:
values = values[funcname]
else:
values = 0
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 expected_type()
return values
@classmethod