diff --git a/VERSION b/VERSION index 6a565cf..71935f0 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1139 \ No newline at end of file +1140 \ No newline at end of file diff --git a/backend/routes/diary.py b/backend/routes/diary.py index 8d85a84..2dfcccb 100644 --- a/backend/routes/diary.py +++ b/backend/routes/diary.py @@ -626,6 +626,14 @@ async def delete_diary(dog_id: int, entry_id: int, user=Depends(get_current_user _own_dog(dog_id, user["id"], conn) except HTTPException: raise HTTPException(403, "Nur der Besitzer darf Einträge löschen.") + # daily_photo_cache aufräumen für alle URLs dieses Eintrags, bevor + # diary_media via CASCADE wegfällt. Sonst zeigt der Cache auf nicht + # mehr existierende Bilder und Heim hat kein Tagesfoto. + media_urls = [r["url"] for r in conn.execute( + "SELECT url FROM diary_media WHERE diary_id=?", (entry_id,) + ).fetchall()] + for u in media_urls: + conn.execute("DELETE FROM daily_photo_cache WHERE photo_url=?", (u,)) conn.execute( "DELETE FROM diary WHERE id=? AND dog_id=?", (entry_id, dog_id) ) @@ -784,6 +792,9 @@ async def delete_media_item(dog_id: int, entry_id: int, media_id: int, if file_path: try: os.remove(file_path) except OSError: pass + # daily_photo_cache mit-bereinigen falls das Bild als Tagesfoto + # gewählt war (sonst lädt der Client 404). + conn.execute("DELETE FROM daily_photo_cache WHERE photo_url=?", (row["url"],)) conn.execute("DELETE FROM diary_media WHERE id=?", (media_id,)) diff --git a/backend/routes/dogs.py b/backend/routes/dogs.py index 9c414d8..cade578 100644 --- a/backend/routes/dogs.py +++ b/backend/routes/dogs.py @@ -251,6 +251,21 @@ async def get_welcome_dashboard(dog_id: int, user=Depends(get_current_user)): (dog_id, today_iso) ).fetchone() + # Cache validieren: zeigt der Eintrag auf eine noch existierende + # Tagebuch-Foto-URL? Wenn der User das Bild gelöscht hat, bliebe + # sonst eine tote URL im Cache → Client lädt 404 → kein Hintergrund. + if cached and cached["photo_url"]: + still_there = conn.execute( + "SELECT 1 FROM diary_media WHERE url=? AND media_type='image' LIMIT 1", + (cached["photo_url"],) + ).fetchone() + if not still_there: + conn.execute( + "DELETE FROM daily_photo_cache WHERE dog_id=? AND datum=?", + (dog_id, today_iso) + ) + cached = None + random_photo = None if cached and cached["photo_url"]: random_photo = { diff --git a/backend/static/index.html b/backend/static/index.html index 6f4b310..31dbe9b 100644 --- a/backend/static/index.html +++ b/backend/static/index.html @@ -86,14 +86,14 @@