Projektarbeit-MYP/backend/config_optimized.py

73 lines
2.2 KiB
Python

"""
Optimized configuration for Raspberry Pi deployment
"""
import os
class OptimizedConfig:
"""Configuration for performance-optimized deployment on Raspberry Pi"""
# Performance optimization flags
OPTIMIZED_MODE = True
USE_MINIFIED_ASSETS = True
DISABLE_ANIMATIONS = True
LIMIT_GLASSMORPHISM = True
# Flask performance settings
DEBUG = False
TESTING = False
SEND_FILE_MAX_AGE_DEFAULT = 31536000 # 1 year cache for static files
# Template settings
TEMPLATES_AUTO_RELOAD = False
EXPLAIN_TEMPLATE_LOADING = False
# Session configuration
SESSION_COOKIE_SECURE = True
SESSION_COOKIE_HTTPONLY = True
SESSION_COOKIE_SAMESITE = 'Lax'
# Performance optimizations
MAX_CONTENT_LENGTH = 16 * 1024 * 1024 # 16MB max upload
JSON_SORT_KEYS = False
JSONIFY_PRETTYPRINT_REGULAR = False
# Database optimizations
SQLALCHEMY_ECHO = False
SQLALCHEMY_TRACK_MODIFICATIONS = False
SQLALCHEMY_ENGINE_OPTIONS = {
'pool_size': 5,
'pool_recycle': 3600,
'pool_pre_ping': True,
'connect_args': {
'check_same_thread': False
}
}
# Cache configuration
CACHE_TYPE = 'simple'
CACHE_DEFAULT_TIMEOUT = 300
CACHE_KEY_PREFIX = 'myp_'
# Static file caching headers
SEND_FILE_MAX_AGE_DEFAULT = 31536000 # 1 year
@staticmethod
def init_app(app):
"""Initialize application with optimized settings"""
# Set optimized template
app.jinja_env.globals['optimized_mode'] = True
app.jinja_env.globals['base_template'] = 'base-optimized.html'
# Add cache headers for static files
@app.after_request
def add_cache_headers(response):
if 'static' in response.headers.get('Location', ''):
response.headers['Cache-Control'] = 'public, max-age=31536000'
response.headers['Vary'] = 'Accept-Encoding'
return response
# Disable unnecessary features
app.config['EXPLAIN_TEMPLATE_LOADING'] = False
app.config['TEMPLATES_AUTO_RELOAD'] = False
print("🚀 Running in OPTIMIZED mode for Raspberry Pi")