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
|
|
@ -1278,21 +1278,26 @@ except Exception:
|
|||
# ------------------------------------------------------------------
|
||||
@router.post("/training-tip")
|
||||
async def training_tip(user=Depends(require_social_media)):
|
||||
# Übung wählen die noch nicht als Social-Post verwendet wurde
|
||||
# Übung wählen die noch nicht als Social-Post verwendet wurde.
|
||||
# Per SQL: zuerst eine unbenutzte zufällig wählen, sonst Reset (irgendeine).
|
||||
with db() as conn:
|
||||
used = {r["exercise_id"] for r in conn.execute(
|
||||
"SELECT exercise_id FROM social_content WHERE exercise_id IS NOT NULL"
|
||||
).fetchall()}
|
||||
all_ex = conn.execute(
|
||||
"SELECT * FROM training_exercises ORDER BY RANDOM()"
|
||||
).fetchall()
|
||||
row = conn.execute(
|
||||
"""SELECT * FROM training_exercises
|
||||
WHERE exercise_id NOT IN (
|
||||
SELECT exercise_id FROM social_content WHERE exercise_id IS NOT NULL
|
||||
)
|
||||
ORDER BY RANDOM() LIMIT 1"""
|
||||
).fetchone()
|
||||
if not row:
|
||||
# Alle durch — Reset: irgendeine zufällige nehmen
|
||||
row = conn.execute(
|
||||
"SELECT * FROM training_exercises ORDER BY RANDOM() LIMIT 1"
|
||||
).fetchone()
|
||||
|
||||
unused = [e for e in all_ex if e["exercise_id"] not in used]
|
||||
pool = unused if unused else list(all_ex) # Reset wenn alle durch
|
||||
if not pool:
|
||||
if not row:
|
||||
raise HTTPException(404, "Keine Übungen gefunden.")
|
||||
|
||||
ex = dict(pool[0])
|
||||
ex = dict(row)
|
||||
stil = random.choice(_TRAINING_STILE)
|
||||
schritte_list = json.loads(ex["schritte"] or "[]")
|
||||
schritte_text = "\n".join(f" {i+1}. {s}" for i, s in enumerate(schritte_list[:4]))
|
||||
|
|
@ -1563,8 +1568,10 @@ async def pflege_tipp(breed_id: Optional[int] = None, user=Depends(require_socia
|
|||
(breed_id,),
|
||||
).fetchone()
|
||||
|
||||
# LIMIT 100 deckelt das Result-Set ab (Tabelle hat aktuell ~43 Einträge);
|
||||
# der Python-Filter unten braucht mehrere Kandidaten für Fell-Typ-Auswahl.
|
||||
tipps = conn.execute(
|
||||
"SELECT * FROM pflege_tipps ORDER BY RANDOM()"
|
||||
"SELECT * FROM pflege_tipps ORDER BY RANDOM() LIMIT 100"
|
||||
).fetchall()
|
||||
|
||||
# Noch nicht verwendete bevorzugen
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue