Fix caching

This commit is contained in:
2020-10-15 17:32:18 +01:00
parent 3d7ff435c9
commit bb4d31477e
9 changed files with 21 additions and 22 deletions

View File

@@ -152,17 +152,19 @@ LOGGING = {
} }
} }
# Caching
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.db.DatabaseCache',
'LOCATION': 'cache_table',
}
}
# Tests lock up SQLite otherwise # Tests lock up SQLite otherwise
if DEBUG or STAGING or CI: if DEBUG or STAGING or CI:
CACHES['default'] = { CACHES = {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache' 'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache'
}
}
else:
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.db.DatabaseCache',
'LOCATION': 'cache_table',
}
} }
RAVEN_CONFIG = { RAVEN_CONFIG = {

View File

@@ -89,10 +89,7 @@ def screenshot_failure_cls(cls):
# Checks if animation is done # Checks if animation is done
class animation_is_finished(object): class animation_is_finished():
def __init__(self):
pass
def __call__(self, driver): def __call__(self, driver):
numberAnimating = driver.execute_script('return $(":animated").length') numberAnimating = driver.execute_script('return $(":animated").length')
finished = numberAnimating == 0 finished = numberAnimating == 0

View File

@@ -20,12 +20,11 @@ from RIGS import models, forms
from assets import models as asset_models from assets import models as asset_models
from functools import reduce 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 from django.utils.decorators import method_decorator
# Displays the current rig count along with a few other bits and pieces # 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): class Index(generic.TemplateView):
template_name = 'index.html' template_name = 'index.html'

View File

@@ -141,8 +141,6 @@ def send_admin_awaiting_approval_email(user, request, **kwargs):
user_activated.connect(send_admin_awaiting_approval_email) user_activated.connect(send_admin_awaiting_approval_email)
# TODO Move
def update_cache(sender, instance, created, **kwargs): def update_cache(sender, instance, created, **kwargs):
cache.clear() cache.clear()

View File

@@ -1,4 +1,6 @@
{% load namewithnotes from filters %} {% load namewithnotes from filters %}
{% load cache %}
{% cache None event_table request.user %}
<div class="table-responsive"> <div class="table-responsive">
<table class="table mb-0"> <table class="table mb-0">
<thead> <thead>
@@ -102,3 +104,4 @@
</tbody> </tbody>
</table> </table>
</div> </div>
{% endcache %}

View File

@@ -32,4 +32,3 @@
</div> </div>
</div> </div>
</div> </div>

View File

@@ -4,8 +4,10 @@
{% load humanize %} {% load humanize %}
{% load paginator from filters %} {% load paginator from filters %}
{% load to_class_name from filters %} {% load to_class_name from filters %}
{% load cache %}
{% block content %} {% block content %}
{% cache None feed_data request.user %}
<div class="list-group-item"> <div class="list-group-item">
<div class="media"> <div class="media">
{% for version in object_list %} {% for version in object_list %}
@@ -48,4 +50,5 @@
</div> </div>
</div> </div>
</div> </div>
{% endcache %}
{% endblock %} {% endblock %}

View File

@@ -7,12 +7,11 @@ from PyRIGS.decorators import (api_key_required, has_oembed,
permission_required_with_403) permission_required_with_403)
from RIGS import finance, ical, models, rigboard, views, hs from RIGS import finance, ical, models, rigboard, views, hs
from versioning import views from versioning import views
from django.views.decorators.cache import cache_page
from django.apps import apps from django.apps import apps
urlpatterns = [ urlpatterns = [
path('rigboard/activity/feed/', 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'), name='activity_feed'),
] ]

View File

@@ -15,7 +15,7 @@ from django.apps import apps
from reversion import revisions as reversion from reversion import revisions as reversion
from versioning.versioning import RIGSVersion 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 from django.utils.decorators import method_decorator
@@ -78,7 +78,6 @@ class ActivityTable(generic.ListView):
return context return context
@method_decorator(never_cache, name='dispatch') # Disable browser based caching
class ActivityFeed(generic.ListView): # Appears on homepage class ActivityFeed(generic.ListView): # Appears on homepage
model = RIGSVersion model = RIGSVersion
template_name = "activity_feed_data.html" template_name = "activity_feed_data.html"