Cache more object lists

master
Mark Veidemanis 1 year ago
parent 40a710f41e
commit 5d6f96bbf3
Signed by: m
GPG Key ID: 5ACFCEED46C0904F

@ -67,7 +67,9 @@ MIDDLEWARE = [
"debug_toolbar.middleware.DebugToolbarMiddleware", "debug_toolbar.middleware.DebugToolbarMiddleware",
"django.middleware.security.SecurityMiddleware", "django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware", "django.contrib.sessions.middleware.SessionMiddleware",
# 'django.middleware.cache.UpdateCacheMiddleware',
"django.middleware.common.CommonMiddleware", "django.middleware.common.CommonMiddleware",
# 'django.middleware.cache.FetchFromCacheMiddleware',
"django.middleware.csrf.CsrfViewMiddleware", "django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware", "django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware", "django.contrib.messages.middleware.MessageMiddleware",

@ -1,48 +1,47 @@
{% load static %} {% load static %}
{% load cache %}
{% for plan in plans %} {% cache 600 objects_plans request.user.id plans %}
{% for plan in plans %}
<div class="box">
<div class="box"> <article class="media">
<article class="media"> <div class="media-left">
<div class="media-left"> <figure class="image is-64x64">
<figure class="image is-64x64"> <img src="{% static plan.image %}" alt="Image">
<img src="{% static plan.image %}" alt="Image"> </figure>
</figure>
</div>
<div class="media-content">
<div class="content">
<p>
<strong>{{ plan.name }}</strong> <small>£{{ plan.cost }}</small>
{% if plan in user_plans %}
<i class="fas fa-check" aria-hidden="true"></i>
{% endif %}
<br>
{{ plan.description }}
</p>
</div> </div>
<nav class="level is-mobile"> <div class="media-content">
<div class="level-left"> <div class="content">
{% if plan not in user_plans %} <p>
<a class="level-item" href="/order/{{ plan.name }}"> <strong>{{ plan.name }}</strong> <small>£{{ plan.cost }}</small>
<span class="icon is-small has-text-success"> {% if plan in user_plans %}
<i class="fas fa-plus" aria-hidden="true"></i> <i class="fas fa-check" aria-hidden="true"></i>
</span> {% endif %}
</a> <br>
{% endif %} {{ plan.description }}
</p>
{% if plan in user_plans %}
<a class="level-item" href="/cancel_subscription/{{ plan.name }}">
<span class="icon is-small has-text-info">
<i class="fas fa-cancel" aria-hidden="true"></i>
</span>
</a>
{% endif %}
</div> </div>
</nav> <nav class="level is-mobile">
</div> <div class="level-left">
</article> {% if plan not in user_plans %}
</div> <a class="level-item" href="/order/{{ plan.name }}">
{% endfor %} <span class="icon is-small has-text-success">
<i class="fas fa-plus" aria-hidden="true"></i>
</span>
</a>
{% endif %}
{% if plan in user_plans %}
<a class="level-item" href="/cancel_subscription/{{ plan.name }}">
<span class="icon is-small has-text-info">
<i class="fas fa-cancel" aria-hidden="true"></i>
</span>
</a>
{% endif %}
</div>
</nav>
</div>
</article>
</div>
{% endfor %}
{% endcache %}

@ -1,93 +1,95 @@
{% load cache %}
{% include 'mixins/partials/notify.html' %} {% include 'mixins/partials/notify.html' %}
{% cache 600 objects_rules request.user.id object_list %}
<table <table
class="table is-fullwidth is-hoverable" class="table is-fullwidth is-hoverable"
hx-target="#{{ context_object_name }}-table" hx-target="#{{ context_object_name }}-table"
id="{{ context_object_name }}-table" id="{{ context_object_name }}-table"
hx-swap="outerHTML" hx-swap="outerHTML"
hx-trigger="{{ context_object_name_singular }}Event from:body" hx-trigger="{{ context_object_name_singular }}Event from:body"
hx-get="{{ list_url }}"> hx-get="{{ list_url }}">
<thead> <thead>
<th>id</th> <th>id</th>
<th>user</th> <th>user</th>
<th>name</th> <th>name</th>
<th>interval</th> <th>interval</th>
<th>window</th> <th>window</th>
<th>priority</th> <th>priority</th>
<th>topic</th> <th>topic</th>
<th>enabled</th> <th>enabled</th>
<th>data length</th> <th>data length</th>
<th>match</th> <th>match</th>
<th>actions</th> <th>actions</th>
</thead> </thead>
{% for item in object_list %} {% for item in object_list %}
<tr> <tr>
<td><a href="/?query=*&source=all&rule={{ item.id }}">{{ item.id }}</a></td> <td><a href="/?query=*&source=all&rule={{ item.id }}">{{ item.id }}</a></td>
<td>{{ item.user }}</td> <td>{{ item.user }}</td>
<td>{{ item.name }}</td> <td>{{ item.name }}</td>
<td>{{ item.interval }}s</td> <td>{{ item.interval }}s</td>
<td>{{ item.window|default_if_none:"—" }}</td> <td>{{ item.window|default_if_none:"—" }}</td>
<td>{{ item.priority }}</td> <td>{{ item.priority }}</td>
<td>{{ item.topic|default_if_none:"—" }}</td> <td>{{ item.topic|default_if_none:"—" }}</td>
<td> <td>
{% if item.enabled %} {% if item.enabled %}
<span class="icon"> <span class="icon">
<i class="fa-solid fa-check"></i> <i class="fa-solid fa-check"></i>
</span>
{% else %}
<span class="icon">
<i class="fa-solid fa-xmark"></i>
</span>
{% endif %}
</td>
<td>{{ item.data|length }}</td>
<td>{{ item.matches }}</td>
<td>
<div class="buttons">
<button
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-get="{% url 'rule_update' type=type pk=item.id %}"
hx-trigger="click"
hx-target="#{{ type }}s-here"
hx-swap="innerHTML"
class="button">
<span class="icon-text">
<span class="icon">
<i class="fa-solid fa-pencil"></i>
</span>
</span> </span>
</button> {% else %}
<button <span class="icon">
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}' <i class="fa-solid fa-xmark"></i>
hx-delete="{% url 'rule_delete' type=type pk=item.id %}"
hx-trigger="click"
hx-target="#modals-here"
hx-swap="innerHTML"
hx-confirm="Are you sure you wish to delete {{ item.name }}?"
class="button">
<span class="icon-text">
<span class="icon">
<i class="fa-solid fa-xmark"></i>
</span>
</span> </span>
</button> {% endif %}
<button </td>
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}' <td>{{ item.data|length }}</td>
hx-post="{% url 'rule_clear' type=type pk=item.id %}" <td>{{ item.matches }}</td>
hx-trigger="click" <td>
hx-target="#modals-here" <div class="buttons">
hx-swap="innerHTML" <button
hx-confirm="Are you sure you wish to clear matches for {{ item.name }}?" hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
class="button"> hx-get="{% url 'rule_update' type=type pk=item.id %}"
<span class="icon-text"> hx-trigger="click"
<span class="icon"> hx-target="#{{ type }}s-here"
<i class="fa-solid fa-arrow-rotate-right"></i> hx-swap="innerHTML"
class="button">
<span class="icon-text">
<span class="icon">
<i class="fa-solid fa-pencil"></i>
</span>
</span> </span>
</span> </button>
</button> <button
</div> hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
</td> hx-delete="{% url 'rule_delete' type=type pk=item.id %}"
</tr> hx-trigger="click"
{% endfor %} hx-target="#modals-here"
hx-swap="innerHTML"
hx-confirm="Are you sure you wish to delete {{ item.name }}?"
class="button">
<span class="icon-text">
<span class="icon">
<i class="fa-solid fa-xmark"></i>
</span>
</span>
</button>
<button
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-post="{% url 'rule_clear' type=type pk=item.id %}"
hx-trigger="click"
hx-target="#modals-here"
hx-swap="innerHTML"
hx-confirm="Are you sure you wish to clear matches for {{ item.name }}?"
class="button">
<span class="icon-text">
<span class="icon">
<i class="fa-solid fa-arrow-rotate-right"></i>
</span>
</span>
</button>
</div>
</td>
</tr>
{% endfor %}
</table> </table>
{% endcache %}
Loading…
Cancel
Save