Optimise performance with caching

This commit is contained in:
Mark Veidemanis 2023-02-11 14:00:09 +00:00
parent 1f43a00c7a
commit 57078c10c1
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
5 changed files with 337 additions and 293 deletions

View File

@ -54,6 +54,24 @@ INSTALLED_APPS = [
# "otp_yubikey", # "otp_yubikey",
"mixins", "mixins",
] ]
# Performance optimisations
CACHES = {
"default": {
"BACKEND": "django.core.cache.backends.redis.RedisCache",
"LOCATION": "unix:///var/run/socks/redis.sock",
"OPTIONS": {
"db": "10",
"parser_class": "redis.connection.PythonParser",
"pool_class": "redis.BlockingConnectionPool",
},
}
}
# CACHE_MIDDLEWARE_ALIAS
# CACHE_MIDDLEWARE_SECONDS
# CACHE_MIDDLEWARE_KEY_PREFIX
CRISPY_TEMPLATE_PACK = "bulma" CRISPY_TEMPLATE_PACK = "bulma"
CRISPY_ALLOWED_TEMPLATE_PACKS = ("bulma",) CRISPY_ALLOWED_TEMPLATE_PACKS = ("bulma",)
DJANGO_TABLES2_TEMPLATE = "django-tables2/bulma.html" DJANGO_TABLES2_TEMPLATE = "django-tables2/bulma.html"
@ -69,6 +87,9 @@ MIDDLEWARE = [
"django.contrib.messages.middleware.MessageMiddleware", "django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware", "django.middleware.clickjacking.XFrameOptionsMiddleware",
"django_htmx.middleware.HtmxMiddleware", "django_htmx.middleware.HtmxMiddleware",
# 'django.middleware.cache.UpdateCacheMiddleware',
# 'django.middleware.common.CommonMiddleware',
# 'django.middleware.cache.FetchFromCacheMiddleware',
] ]
ROOT_URLCONF = "app.urls" ROOT_URLCONF = "app.urls"

View File

@ -1,8 +1,10 @@
{% load static %} {% load static %}
{% load has_plan %} {% load has_plan %}
{% load cache %}
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en-GB"> <html lang="en-GB">
{% cache 600 head %}
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
@ -195,8 +197,10 @@
</script> </script>
<!-- End Piwik Code --> <!-- End Piwik Code -->
</head> </head>
{% endcache %}
<body> <body>
{% cache 600 nav request.user.id %}
<nav class="navbar" role="navigation" aria-label="main navigation"> <nav class="navbar" role="navigation" aria-label="main navigation">
<div class="navbar-brand"> <div class="navbar-brand">
<a class="navbar-item" href="{% url 'home' %}"> <a class="navbar-item" href="{% url 'home' %}">
@ -310,6 +314,7 @@
</div> </div>
</div> </div>
</nav> </nav>
{% endcache %}
<script> <script>
let deferredPrompt; let deferredPrompt;
const addBtn = document.querySelector('.add-button'); const addBtn = document.querySelector('.add-button');

View File

@ -43,6 +43,8 @@ services:
- ${PORTAINER_GIT_DIR}:/code - ${PORTAINER_GIT_DIR}:/code
- ${APP_DATABASE_FILE}:/conf/db.sqlite3 - ${APP_DATABASE_FILE}:/conf/db.sqlite3
- fisk_static:${STATIC_ROOT} - fisk_static:${STATIC_ROOT}
volumes_from:
- tmp
env_file: env_file:
- stack.env - stack.env
@ -58,6 +60,8 @@ services:
- ${PORTAINER_GIT_DIR}:/code - ${PORTAINER_GIT_DIR}:/code
- ${APP_DATABASE_FILE}:/conf/db.sqlite3 - ${APP_DATABASE_FILE}:/conf/db.sqlite3
- fisk_static:${STATIC_ROOT} - fisk_static:${STATIC_ROOT}
volumes_from:
- tmp
env_file: env_file:
- stack.env - stack.env
@ -98,24 +102,33 @@ services:
volumes: volumes:
- /var/run/socks - /var/run/socks
# redis: # For caching
# image: redis redis:
# command: redis-server /etc/redis.conf image: redis
# ulimits: container_name: redis_fisk
# nproc: 65535 command: redis-server /etc/redis.conf
# nofile: ulimits:
# soft: 65535 nproc: 65535
# hard: 65535 nofile:
# volumes: soft: 65535
# - ${PORTAINER_GIT_DIR}/docker/redis.conf:/etc/redis.conf hard: 65535
# - redis_data:/data volumes:
# volumes_from: - ${PORTAINER_GIT_DIR}/docker/redis.conf:/etc/redis.conf
# - tmp - fisk_redis_data:/data
# healthcheck: volumes_from:
# test: "redis-cli -s /var/run/redis/redis.sock ping" - tmp
# interval: 2s healthcheck:
# timeout: 2s test: "redis-cli -s /var/run/socks/redis.sock ping"
# retries: 15 interval: 2s
timeout: 2s
retries: 15
# pyroscope:
# image: "pyroscope/pyroscope:latest"
# ports:
# - "4040:4040"
# command:
# - "server"
networks: networks:
default: default:
@ -127,3 +140,4 @@ networks:
volumes: volumes:
fisk_static: {} fisk_static: {}
fisk_redis_data: {}

View File

@ -1,2 +1,2 @@
unixsocket /var/run/redis/redis.sock unixsocket /var/run/socks/redis.sock
unixsocketperm 777 unixsocketperm 777

View File

@ -22,3 +22,7 @@ oandapyV20
glom glom
elasticsearch elasticsearch
git+https://git.zm.is/XF/django-crud-mixins git+https://git.zm.is/XF/django-crud-mixins
# pyroscope-io
# For caching
redis
hiredis