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
|
|
@ -5,10 +5,28 @@ from pydantic import BaseModel
|
|||
from typing import Optional
|
||||
from database import db
|
||||
from auth import get_current_user_optional, require_admin
|
||||
from cache import ttl_cache
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Öffentliche, aktive FAQ-Liste – statisch, 1h TTL-Cache.
|
||||
# Admin-Pfad (?all=1) wird NICHT gecached.
|
||||
# Wird bei jedem schreibenden Admin-Endpoint unten invalidiert.
|
||||
# ------------------------------------------------------------------
|
||||
@ttl_cache(ttl=3600)
|
||||
def _load_active_help_articles() -> list[dict]:
|
||||
with db() as conn:
|
||||
rows = conn.execute(
|
||||
"SELECT id, kategorie, frage, antwort, sort_order, aktiv "
|
||||
"FROM help_articles "
|
||||
"WHERE aktiv = 1 "
|
||||
"ORDER BY kategorie, sort_order, id"
|
||||
).fetchall()
|
||||
return [dict(r) for r in rows]
|
||||
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Schemas
|
||||
# ------------------------------------------------------------------
|
||||
|
|
@ -39,22 +57,17 @@ def get_help(
|
|||
is_admin = user and user.get("rolle") == "admin"
|
||||
show_all = all == 1 and is_admin
|
||||
|
||||
with db() as conn:
|
||||
if show_all:
|
||||
if show_all:
|
||||
with db() as conn:
|
||||
rows = conn.execute(
|
||||
"SELECT id, kategorie, frage, antwort, sort_order, aktiv "
|
||||
"FROM help_articles "
|
||||
"ORDER BY kategorie, sort_order, id"
|
||||
).fetchall()
|
||||
else:
|
||||
rows = conn.execute(
|
||||
"SELECT id, kategorie, frage, antwort, sort_order, aktiv "
|
||||
"FROM help_articles "
|
||||
"WHERE aktiv = 1 "
|
||||
"ORDER BY kategorie, sort_order, id"
|
||||
).fetchall()
|
||||
return [dict(r) for r in rows]
|
||||
|
||||
return [dict(r) for r in rows]
|
||||
# Öffentliche, aktive Artikel kommen aus dem Cache
|
||||
return _load_active_help_articles()
|
||||
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
|
|
@ -68,6 +81,7 @@ def create_article(body: ArticleCreate, admin=Depends(require_admin)):
|
|||
"VALUES (?, ?, ?, ?, ?)",
|
||||
(body.kategorie, body.frage, body.antwort, body.sort_order, body.aktiv),
|
||||
)
|
||||
_load_active_help_articles.cache_clear()
|
||||
return {"ok": True, "id": cur.lastrowid}
|
||||
|
||||
|
||||
|
|
@ -85,6 +99,7 @@ def update_article(article_id: int, body: ArticleUpdate, admin=Depends(require_a
|
|||
f"UPDATE help_articles SET {set_clause} WHERE id=?",
|
||||
(*updates.values(), article_id),
|
||||
)
|
||||
_load_active_help_articles.cache_clear()
|
||||
return {"ok": True}
|
||||
|
||||
|
||||
|
|
@ -95,4 +110,5 @@ def update_article(article_id: int, body: ArticleUpdate, admin=Depends(require_a
|
|||
def delete_article(article_id: int, admin=Depends(require_admin)):
|
||||
with db() as conn:
|
||||
conn.execute("DELETE FROM help_articles WHERE id=?", (article_id,))
|
||||
_load_active_help_articles.cache_clear()
|
||||
return {"ok": True}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue