From 27c7238a82dc1cb6220d4ba41e909f0919ee8dd3 Mon Sep 17 00:00:00 2001 From: badbl0cks <4161747+badbl0cks@users.noreply.github.com> Date: Sat, 15 Mar 2025 21:51:23 -0700 Subject: [PATCH] Enable caching via DB and update cache timeouts --- accounts/migrations/0001_initial.py | 2 +- cards/migrations/0001_initial.py | 2 +- cards/templatetags/card_multiselect.py | 5 +- django_project/settings.py | 4 +- home/views.py | 1 - reset-db_make-migrations_seed-data.sh | 3 + theme/templates/home/home.html | 8 +- theme/templatetags/card_multiselect.html | 2 +- theme/templatetags/trade_acceptance.html | 84 ++--- theme/templatetags/trade_offer.html | 451 +++++++++++------------ trades/migrations/0001_initial.py | 2 +- 11 files changed, 281 insertions(+), 283 deletions(-) diff --git a/accounts/migrations/0001_initial.py b/accounts/migrations/0001_initial.py index 28426c2..db8f4b6 100644 --- a/accounts/migrations/0001_initial.py +++ b/accounts/migrations/0001_initial.py @@ -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.validators diff --git a/cards/migrations/0001_initial.py b/cards/migrations/0001_initial.py index 76f7364..b13630e 100644 --- a/cards/migrations/0001_initial.py +++ b/cards/migrations/0001_initial.py @@ -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 from django.db import migrations, models diff --git a/cards/templatetags/card_multiselect.py b/cards/templatetags/card_multiselect.py index 581716d..ba0fdb5 100644 --- a/cards/templatetags/card_multiselect.py +++ b/cards/templatetags/card_multiselect.py @@ -4,7 +4,7 @@ from cards.models import Card register = template.Library() @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. @@ -50,6 +50,5 @@ def card_multiselect(field_name, label, placeholder, cards=None, selected_values 'cards': cards, 'placeholder': placeholder, 'selected_values': list(selected_cards.keys()), - 'cache_timeout': cache_timeout, - 'cache_key': cache_key, + 'cache_timeout': cache_timeout } \ No newline at end of file diff --git a/django_project/settings.py b/django_project/settings.py index 9534160..1571649 100644 --- a/django_project/settings.py +++ b/django_project/settings.py @@ -286,7 +286,7 @@ if DEBUG: else: CACHES = { "default": { - "BACKEND": "django.core.cache.backends.locmem.LocMemCache", - "LOCATION": "unique-snowflake", + "BACKEND": "django.core.cache.backends.db.DatabaseCache", + "LOCATION": "site_cache", } } \ No newline at end of file diff --git a/home/views.py b/home/views.py index 7c47e08..176ed9f 100644 --- a/home/views.py +++ b/home/views.py @@ -10,7 +10,6 @@ from django.views.decorators.cache import cache_page from django.template.response import TemplateResponse from django.http import HttpResponseRedirect -@method_decorator(cache_page(60), name='get') class HomePageView(TemplateView): template_name = "home/home.html" diff --git a/reset-db_make-migrations_seed-data.sh b/reset-db_make-migrations_seed-data.sh index e1d4f31..d19f192 100755 --- a/reset-db_make-migrations_seed-data.sh +++ b/reset-db_make-migrations_seed-data.sh @@ -22,5 +22,8 @@ uv run python manage.py migrate echo "Loading seed data..." uv run python manage.py loaddata seed/0* +echo "Creating cache table..." +uv run python manage.py createcachetable + echo "Seeding default friend codes..." uv run python manage.py seed_default_friend_codes \ No newline at end of file diff --git a/theme/templates/home/home.html b/theme/templates/home/home.html index 4d6dc8e..5b8aee0 100644 --- a/theme/templates/home/home.html +++ b/theme/templates/home/home.html @@ -85,9 +85,9 @@