Perf: 9 Performance-Fixes — SW by-v1072
Backend: - DB: 3 neue Indizes (forum_posts thread+user, routes user) — Forum/Routen-Queries - Caching: cache.py (TTL-Cache ohne neue Dependency) für 5 statische Listen (training_exercises, pflege_tipps, wiki_stats, wiki_gruppen, help_articles) - diary.py + breeder_photos.py: Bildverarbeitung (ffmpeg/PIL/EXIF) per run_in_executor → blockiert Event-Loop nicht mehr - scheduler.py: 11 kollidierende Jobs auf 5-Min-Intervalle gestaggert, coalesce=True - social.py: ORDER BY RANDOM() ohne LIMIT in 2 Stellen gefixt - alerts.py: Haversine-Loop bekommt SQL-Bounding-Box-Vorfilter Frontend: - sw.js: Tile-Cache mit LRU-Eviction (max 500 Einträge) - admin.js: Event-Listener-Leak — Tab-Klicks per Delegation statt N Listener - api.js: compressImage() Helper — Client-seitiges Resize auf max 2000px (HEIC/Videos/<500KB unverändert), integriert in 8 Upload-Stellen (diary, dog-profile×2, walks, poison, lost, health×2) Bump APP_VER 1071 → 1072 (sw.js, app.js, main.py, index.html)
This commit is contained in:
parent
3abf974d29
commit
c03884cb81
23 changed files with 461 additions and 120 deletions
|
|
@ -10,6 +10,7 @@ from pydantic import BaseModel
|
|||
from database import db
|
||||
from auth import get_current_user, get_current_user_optional
|
||||
from ratelimit import check as rl_check, block_ip
|
||||
from cache import ttl_cache
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
MEDIA_DIR = os.getenv("MEDIA_DIR", "/data/media")
|
||||
|
|
@ -81,16 +82,34 @@ def _quiz_score(rasse: dict, params: dict) -> int:
|
|||
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# GET /api/wiki/stats — Seed-Status
|
||||
# GET /api/wiki/stats — Seed-Status (1h TTL-Cache, statische Anzahl)
|
||||
# ------------------------------------------------------------------
|
||||
@router.get("/stats")
|
||||
async def get_stats():
|
||||
@ttl_cache(ttl=3600)
|
||||
def _wiki_stats() -> dict:
|
||||
with db() as conn:
|
||||
row = conn.execute("SELECT COUNT(*) as total FROM wiki_rassen").fetchone()
|
||||
total = row["total"] if row else 0
|
||||
return {"total_breeds": total, "seeded": total > 0}
|
||||
|
||||
|
||||
@router.get("/stats")
|
||||
async def get_stats():
|
||||
return _wiki_stats()
|
||||
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Gruppen-Liste für Filter-Dropdown – statisch, 1h TTL-Cache
|
||||
# ------------------------------------------------------------------
|
||||
@ttl_cache(ttl=3600)
|
||||
def _wiki_gruppen() -> list[str]:
|
||||
with db() as conn:
|
||||
rows = conn.execute(
|
||||
"SELECT DISTINCT gruppe FROM wiki_rassen "
|
||||
"WHERE gruppe IS NOT NULL ORDER BY gruppe"
|
||||
).fetchall()
|
||||
return [r["gruppe"] for r in rows]
|
||||
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# GET /api/wiki/rassen — alle Rassen (Übersicht, paginiert)
|
||||
# ------------------------------------------------------------------
|
||||
|
|
@ -134,15 +153,13 @@ async def get_rassen(
|
|||
SELECT COUNT(*) as total FROM wiki_rassen {where}
|
||||
""", args).fetchone()
|
||||
|
||||
# Alle Gruppen für Filter-Dropdown
|
||||
gruppen_rows = conn.execute(
|
||||
"SELECT DISTINCT gruppe FROM wiki_rassen WHERE gruppe IS NOT NULL ORDER BY gruppe"
|
||||
).fetchall()
|
||||
# Alle Gruppen für Filter-Dropdown (gecached, 1h TTL)
|
||||
gruppen = _wiki_gruppen()
|
||||
|
||||
return {
|
||||
"breeds": [dict(r) for r in rows],
|
||||
"total": count_row["total"] if count_row else 0,
|
||||
"gruppen": [r["gruppe"] for r in gruppen_rows],
|
||||
"gruppen": gruppen,
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue