Enable caching via DB and update cache timeouts

This commit is contained in:
badblocks 2025-03-15 21:51:23 -07:00
parent 9ce5d525b3
commit 27c7238a82
11 changed files with 281 additions and 283 deletions

View file

@ -1,4 +1,4 @@
# Generated by Django 5.1.2 on 2025-03-15 22:05 # Generated by Django 5.1.2 on 2025-03-16 04:58
import django.contrib.auth.models import django.contrib.auth.models
import django.contrib.auth.validators import django.contrib.auth.validators

View file

@ -1,4 +1,4 @@
# Generated by Django 5.1.2 on 2025-03-15 22:05 # Generated by Django 5.1.2 on 2025-03-16 04:58
import django.db.models.deletion import django.db.models.deletion
from django.db import migrations, models from django.db import migrations, models

View file

@ -4,7 +4,7 @@ from cards.models import Card
register = template.Library() register = template.Library()
@register.inclusion_tag('templatetags/card_multiselect.html') @register.inclusion_tag('templatetags/card_multiselect.html')
def card_multiselect(field_name, label, placeholder, cards=None, selected_values=None, cache_timeout=86400, cache_key="cards_multiselect"): def card_multiselect(field_name, label, placeholder, cards=None, selected_values=None, cache_timeout=86400):
""" """
Renders a multiselect field for choosing cards while supporting quantity data. Renders a multiselect field for choosing cards while supporting quantity data.
@ -50,6 +50,5 @@ def card_multiselect(field_name, label, placeholder, cards=None, selected_values
'cards': cards, 'cards': cards,
'placeholder': placeholder, 'placeholder': placeholder,
'selected_values': list(selected_cards.keys()), 'selected_values': list(selected_cards.keys()),
'cache_timeout': cache_timeout, 'cache_timeout': cache_timeout
'cache_key': cache_key,
} }

View file

@ -286,7 +286,7 @@ if DEBUG:
else: else:
CACHES = { CACHES = {
"default": { "default": {
"BACKEND": "django.core.cache.backends.locmem.LocMemCache", "BACKEND": "django.core.cache.backends.db.DatabaseCache",
"LOCATION": "unique-snowflake", "LOCATION": "site_cache",
} }
} }

View file

@ -10,7 +10,6 @@ from django.views.decorators.cache import cache_page
from django.template.response import TemplateResponse from django.template.response import TemplateResponse
from django.http import HttpResponseRedirect from django.http import HttpResponseRedirect
@method_decorator(cache_page(60), name='get')
class HomePageView(TemplateView): class HomePageView(TemplateView):
template_name = "home/home.html" template_name = "home/home.html"

View file

@ -22,5 +22,8 @@ uv run python manage.py migrate
echo "Loading seed data..." echo "Loading seed data..."
uv run python manage.py loaddata seed/0* uv run python manage.py loaddata seed/0*
echo "Creating cache table..."
uv run python manage.py createcachetable
echo "Seeding default friend codes..." echo "Seeding default friend codes..."
uv run python manage.py seed_default_friend_codes uv run python manage.py seed_default_friend_codes

View file

@ -85,9 +85,9 @@
<div class="grid grid-cols-1 md:grid-cols-2 gap-4"> <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<!-- Featured Offers --> <!-- Featured Offers -->
<div> <div>
{% cache 86400 featured_offers %} {% cache 60 featured_offers %}
<div class="p-4"> <div class="p-4 text-center ">
<h5 class="text-xl text-center font-semibold whitespace-nowrap truncate mb-0">Featured Offers</h5> <h5 class="text-xl font-semibold whitespace-nowrap truncate mb-0">Featured Offers</h5>
</div> </div>
<div class="p-4"> <div class="p-4">
<!-- Tab contents --> <!-- Tab contents -->
@ -139,7 +139,7 @@
<!-- Recent Offers --> <!-- Recent Offers -->
<div> <div>
{% cache 60 recent_offers %} {% cache 60 recent_offers %}
<div class="text-center text-base-content p-4"> <div class="text-center p-4">
<h5 class="text-xl font-semibold whitespace-nowrap truncate mb-0">Recent Offers</h5> <h5 class="text-xl font-semibold whitespace-nowrap truncate mb-0">Recent Offers</h5>
</div> </div>
<div class="p-4"> <div class="p-4">

View file

@ -3,7 +3,7 @@
<span class="label-text">{{ label }}</span> <span class="label-text">{{ label }}</span>
</label> </label>
<select name="{{ field_name }}" id="{{ field_id }}" class="select select-bordered w-full card-multiselect" data-placeholder="{{ placeholder }}" multiple> <select name="{{ field_name }}" id="{{ field_id }}" class="select select-bordered w-full card-multiselect" data-placeholder="{{ placeholder }}" multiple>
{% cache cache_timeout cache_key selected_values|join:"," %} {% cache cache_timeout card_multiselect selected_values|join:"," %}
<option value="" disabled>{{ placeholder }}</option> <option value="" disabled>{{ placeholder }}</option>
{% for card in cards %} {% for card in cards %}
<option <option

View file

@ -1,5 +1,6 @@
{% load gravatar card_badge %} {% load gravatar card_badge cache %}
{% cache 60 trade_acceptance acceptance.pk %}
<div class="card card-border bg-base-100 shadow-lg w-96 md:w-80 lg:w-96"> <div class="card card-border bg-base-100 shadow-lg w-96 md:w-80 lg:w-96">
<!-- Header --> <!-- Header -->
<div class="py-4 mx-2 sm:mx-4"> <div class="py-4 mx-2 sm:mx-4">
@ -49,3 +50,4 @@
</div> </div>
</div> </div>
</div> </div>
{% endcache %}

View file

@ -1,8 +1,6 @@
{% load gravatar card_badge %} {% load gravatar card_badge cache %}
<!-- {% cache 60 trade_offer offer.pk %}
Define the Alpine component only once.
-->
<script> <script>
if (!window.tradeOfferCard) { if (!window.tradeOfferCard) {
window.tradeOfferCard = function() { window.tradeOfferCard = function() {
@ -19,10 +17,6 @@ if (!window.tradeOfferCard) {
} }
</script> </script>
<!--
The outer div now only establishes Alpine's data context.
The dynamic height adjustment (x-init & x-effect with x-ref) has been removed.
-->
<div x-data="tradeOfferCard()" class="transition-all duration-500 trade-offer-card" <div x-data="tradeOfferCard()" class="transition-all duration-500 trade-offer-card"
@toggle-all.window="setBadge($event.detail.expanded)"> @toggle-all.window="setBadge($event.detail.expanded)">
@ -272,3 +266,4 @@ if (!window.tradeOfferCard) {
transform: rotateY(180deg); transform: rotateY(180deg);
} }
</style> </style>
{% endcache %}

View file

@ -1,4 +1,4 @@
# Generated by Django 5.1.2 on 2025-03-15 22:05 # Generated by Django 5.1.2 on 2025-03-16 04:58
import django.db.models.deletion import django.db.models.deletion
from django.db import migrations, models from django.db import migrations, models