From 33d8e26c9b745014b1ede6132bb0b8e046d0993b Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Sat, 11 Feb 2023 17:22:25 +0000 Subject: [PATCH] Use cachalot to invalidate caches --- app/settings.py | 2 ++ core/models.py | 18 +----------------- core/templates/partials/account-list.html | 4 +++- core/templates/partials/assetgroup-list.html | 8 +++----- .../partials/assetrestriction-list.html | 4 +++- core/templates/partials/callback-list.html | 4 +++- core/templates/partials/hook-list.html | 4 +++- core/templates/partials/product-list.html | 5 +++-- core/templates/partials/risk-list.html | 4 +++- core/templates/partials/signal-list.html | 4 +++- core/templates/partials/strategy-list.html | 4 +++- core/templates/partials/trade-list.html | 4 +++- core/templates/partials/trading-time-list.html | 4 +++- .../partials/trend-direction-list.html | 4 +++- core/tests/lib/__init__.py | 0 .../test_crossfilter.py} | 2 +- core/trading/assetfilter.py | 7 +++++++ core/trading/market.py | 3 +++ requirements.txt | 1 + 19 files changed, 51 insertions(+), 35 deletions(-) delete mode 100644 core/tests/lib/__init__.py rename core/tests/{lib/test_market.py => trading/test_crossfilter.py} (99%) create mode 100644 core/trading/assetfilter.py diff --git a/app/settings.py b/app/settings.py index 9754174..efc08e0 100644 --- a/app/settings.py +++ b/app/settings.py @@ -53,6 +53,7 @@ INSTALLED_APPS = [ # "two_factor.plugins.yubikey", # "otp_yubikey", "mixins", + "cachalot", ] @@ -202,6 +203,7 @@ DEBUG_TOOLBAR_PANELS = [ "debug_toolbar.panels.logging.LoggingPanel", "debug_toolbar.panels.redirects.RedirectsPanel", "debug_toolbar.panels.profiling.ProfilingPanel", + "cachalot.panels.CachalotPanel", ] from app.local_settings import * # noqa diff --git a/core/models.py b/core/models.py index 414602c..5ba1a7d 100644 --- a/core/models.py +++ b/core/models.py @@ -418,23 +418,7 @@ class AssetGroup(models.Model): allowed = models.JSONField(null=True, blank=True, default=dict) def __str__(self): - return f"{self.name} ({self.restrictions})" - - @property - def matches(self): - """ - Get the total number of matches for this group. - """ - if isinstance(self.allowed, dict): - truthy_values = [x for x in self.allowed.values() if x is True] - return f"{len(truthy_values)}/{len(self.allowed)}" - - @property - def restrictions(self): - """ - Get the total number of restrictions for this group. - """ - return self.assetrestriction_set.count() + return f"{self.name}" class AssetRestriction(models.Model): diff --git a/core/templates/partials/account-list.html b/core/templates/partials/account-list.html index 348dedd..9a3d0b1 100644 --- a/core/templates/partials/account-list.html +++ b/core/templates/partials/account-list.html @@ -1,6 +1,8 @@ {% load cache %} +{% load cachalot cache %} +{% get_last_invalidation 'core.Account' as last %} {% include 'mixins/partials/notify.html' %} -{% cache 600 objects_accounts request.user.id object_list %} +{% cache 600 objects_accounts request.user.id object_list last %} name - - {% for item in object_list %} @@ -25,8 +25,6 @@ - - diff --git a/core/templates/partials/hook-list.html b/core/templates/partials/hook-list.html index 7650b5f..ffef953 100644 --- a/core/templates/partials/hook-list.html +++ b/core/templates/partials/hook-list.html @@ -1,6 +1,8 @@ {% load cache %} +{% load cachalot cache %} +{% get_last_invalidation 'core.Hook' as last %} {% include 'mixins/partials/notify.html' %} -{% cache 600 objects_hooks request.user.id object_list %} +{% cache 600 objects_hooks request.user.id object_list last %}
description accountstatusrestrictions actions {{ item.name }} {{ item.description }} {{ item.account }}{{ item.matches }}{{ item.restrictions }}
id
diff --git a/core/templates/partials/risk-list.html b/core/templates/partials/risk-list.html index d447c67..5e7321e 100644 --- a/core/templates/partials/risk-list.html +++ b/core/templates/partials/risk-list.html @@ -1,6 +1,8 @@ {% load cache %} +{% load cachalot cache %} +{% get_last_invalidation 'core.RiskModel' as last %} {% include 'mixins/partials/notify.html' %} -{% cache 600 objects_risk request.user.id object_list %} +{% cache 600 objects_risk request.user.id object_list last %}