Use cachalot to invalidate caches

This commit is contained in:
Mark Veidemanis 2023-02-11 17:24:13 +00:00
parent 9fcf5041f0
commit 4ead6ff7c1
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
5 changed files with 9 additions and 14 deletions

View File

@ -44,6 +44,7 @@ INSTALLED_APPS = [
"django_tables2_bulma_template",
"prettyjson",
"mixins",
"cachalot",
]
# Performance optimisations
@ -181,6 +182,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

View File

@ -214,15 +214,6 @@ class NotificationRule(models.Model):
raise ValueError(f"Invalid YAML: {e}")
return parsed
@property
def matches(self):
"""
Get the total number of matches for this rule.
"""
if isinstance(self.match, dict):
truthy_values = [x for x in self.match.values() if x is not False]
return f"{len(truthy_values)}/{len(self.match)}"
def get_notification_settings(self, check=True):
"""
Get the notification settings for this rule.

View File

@ -1,7 +1,8 @@
{% load static %}
{% load cache %}
{% cache 600 objects_plans request.user.id plans %}
{% load cachalot cache %}
{% get_last_invalidation 'core.Plan' as last %}
{% cache 600 objects_plans request.user.id plans last %}
{% for plan in plans %}
<div class="box">
<article class="media">

View File

@ -1,6 +1,8 @@
{% load cache %}
{% load cachalot cache %}
{% get_last_invalidation 'core.NotificationRule' as last %}
{% include 'mixins/partials/notify.html' %}
{% cache 600 objects_rules request.user.id object_list %}
{% cache 600 objects_rules request.user.id object_list last %}
<table
class="table is-fullwidth is-hoverable"
hx-target="#{{ context_object_name }}-table"
@ -18,7 +20,6 @@
<th>topic</th>
<th>enabled</th>
<th>data length</th>
<th>match</th>
<th>actions</th>
</thead>
{% for item in object_list %}
@ -42,7 +43,6 @@
{% endif %}
</td>
<td>{{ item.data|length }}</td>
<td>{{ item.matches }}</td>
<td>
<div class="buttons">
<button

View File

@ -25,3 +25,4 @@ git+https://git.zm.is/XF/django-crud-mixins
# For caching
redis
hiredis
django-cachalot