From bb4d31477e10a8a305917c57128d6ba354e24ef5 Mon Sep 17 00:00:00 2001 From: FreneticScribbler Date: Thu, 15 Oct 2020 17:32:18 +0100 Subject: [PATCH] Fix caching --- PyRIGS/settings.py | 20 +++++++++++--------- PyRIGS/tests/base.py | 5 +---- PyRIGS/views.py | 3 +-- RIGS/signals.py | 2 -- RIGS/templates/partials/event_table.html | 3 +++ versioning/templates/activity_feed.html | 1 - versioning/templates/activity_feed_data.html | 3 +++ versioning/urls.py | 3 +-- versioning/views.py | 3 +-- 9 files changed, 21 insertions(+), 22 deletions(-) diff --git a/PyRIGS/settings.py b/PyRIGS/settings.py index e8d46fed..cb5eac81 100644 --- a/PyRIGS/settings.py +++ b/PyRIGS/settings.py @@ -152,17 +152,19 @@ LOGGING = { } } -# Caching -CACHES = { - 'default': { - 'BACKEND': 'django.core.cache.backends.db.DatabaseCache', - 'LOCATION': 'cache_table', - } -} # Tests lock up SQLite otherwise if DEBUG or STAGING or CI: - CACHES['default'] = { - 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache' + CACHES = { + 'default': { + 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache' + } + } +else: + CACHES = { + 'default': { + 'BACKEND': 'django.core.cache.backends.db.DatabaseCache', + 'LOCATION': 'cache_table', + } } RAVEN_CONFIG = { diff --git a/PyRIGS/tests/base.py b/PyRIGS/tests/base.py index b6b5678d..d8af4237 100644 --- a/PyRIGS/tests/base.py +++ b/PyRIGS/tests/base.py @@ -89,10 +89,7 @@ def screenshot_failure_cls(cls): # Checks if animation is done -class animation_is_finished(object): - def __init__(self): - pass - +class animation_is_finished(): def __call__(self, driver): numberAnimating = driver.execute_script('return $(":animated").length') finished = numberAnimating == 0 diff --git a/PyRIGS/views.py b/PyRIGS/views.py index 855a6c85..a70e36da 100644 --- a/PyRIGS/views.py +++ b/PyRIGS/views.py @@ -20,12 +20,11 @@ from RIGS import models, forms from assets import models as asset_models from functools import reduce -from django.views.decorators.cache import never_cache +from django.views.decorators.cache import never_cache, cache_page from django.utils.decorators import method_decorator # Displays the current rig count along with a few other bits and pieces -@method_decorator(never_cache, name='dispatch') # Disable browser based caching class Index(generic.TemplateView): template_name = 'index.html' diff --git a/RIGS/signals.py b/RIGS/signals.py index 5819fba7..b75dc348 100644 --- a/RIGS/signals.py +++ b/RIGS/signals.py @@ -141,8 +141,6 @@ def send_admin_awaiting_approval_email(user, request, **kwargs): user_activated.connect(send_admin_awaiting_approval_email) -# TODO Move - def update_cache(sender, instance, created, **kwargs): cache.clear() diff --git a/RIGS/templates/partials/event_table.html b/RIGS/templates/partials/event_table.html index 7b15b794..db75554c 100644 --- a/RIGS/templates/partials/event_table.html +++ b/RIGS/templates/partials/event_table.html @@ -1,4 +1,6 @@ {% load namewithnotes from filters %} +{% load cache %} +{% cache None event_table request.user %}
@@ -102,3 +104,4 @@
+{% endcache %} diff --git a/versioning/templates/activity_feed.html b/versioning/templates/activity_feed.html index 6e55acd4..84d16487 100644 --- a/versioning/templates/activity_feed.html +++ b/versioning/templates/activity_feed.html @@ -32,4 +32,3 @@ - diff --git a/versioning/templates/activity_feed_data.html b/versioning/templates/activity_feed_data.html index 25af3337..cbd37ecd 100644 --- a/versioning/templates/activity_feed_data.html +++ b/versioning/templates/activity_feed_data.html @@ -4,8 +4,10 @@ {% load humanize %} {% load paginator from filters %} {% load to_class_name from filters %} +{% load cache %} {% block content %} +{% cache None feed_data request.user %}
{% for version in object_list %} @@ -48,4 +50,5 @@
+{% endcache %} {% endblock %} diff --git a/versioning/urls.py b/versioning/urls.py index 7c8fe5b1..c7f92f2c 100644 --- a/versioning/urls.py +++ b/versioning/urls.py @@ -7,12 +7,11 @@ from PyRIGS.decorators import (api_key_required, has_oembed, permission_required_with_403) from RIGS import finance, ical, models, rigboard, views, hs from versioning import views -from django.views.decorators.cache import cache_page from django.apps import apps urlpatterns = [ path('rigboard/activity/feed/', - cache_page(60 * 10)(permission_required_with_403('RIGS.view_event')(views.ActivityFeed.as_view())), + permission_required_with_403('RIGS.view_event')(views.ActivityFeed.as_view()), name='activity_feed'), ] diff --git a/versioning/views.py b/versioning/views.py index bc32b05f..29ab9cef 100644 --- a/versioning/views.py +++ b/versioning/views.py @@ -15,7 +15,7 @@ from django.apps import apps from reversion import revisions as reversion from versioning.versioning import RIGSVersion -from django.views.decorators.cache import never_cache +from django.views.decorators.cache import never_cache, cache_page from django.utils.decorators import method_decorator @@ -78,7 +78,6 @@ class ActivityTable(generic.ListView): return context -@method_decorator(never_cache, name='dispatch') # Disable browser based caching class ActivityFeed(generic.ListView): # Appears on homepage model = RIGSVersion template_name = "activity_feed_data.html"