AOSSIE-Org / AOSSIE-Org/PictoPy

BUG: Orphan thumbnail files permanently leak disk space when folders are deleted

Đang mở
#1,159 4 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Python
Star
283
Fork
679
Merge trung bình
7 ngày 2 giờ
Pull request đã merge (30 ngày)
3

Mô tả

### Is there an existing issue for this?

- [x] I have searched the existing issues

### What happened?

When a user deletes a folder through **Settings → Folder Management**, the thumbnail image files on disk are never cleaned up. The SQL `ON DELETE CASCADE` removes the image records from the database, but the physical `thumbnail_*.jpg` files in the app's thumbnail directory remain on disk permanently. This causes a silent disk space leak that grows every time a folder is removed.

## Expected Behavior

When a folder is deleted, all associated thumbnail files on disk should also be removed. The `delete_folders` route should query all thumbnail paths for images belonging to the folders being deleted **before** removing the DB records, and then delete those files from disk.

## Root Cause

The `delete_folders` route in `backend/app/routes/folders.py` only calls the database batch delete function which performs a SQL DELETE — it never touches the filesystem to remove the corresponding thumbnail files.

Interestingly, the sync/obsolete flow in `backend/app/utils/images.py` (`image_util_remove_obsolete_images`) **does** correctly clean up thumbnails when images are found to be missing from the filesystem — but this function is never called during the folder deletion flow.

The same problem also exists in `folder_util_delete_obsolete_folders` in `backend/app/utils/folders.py` — it deletes folder records from the database without any thumbnail cleanup.

## Steps to Reproduce

1. Open PictoPy and add a folder containing images (e.g., 50 photos).
2. Wait for processing to complete (thumbnails generated).
3. Note the files in the thumbnails directory (`~/.local/share/PictoPy/thumbnails/`).
4. Go to **Settings → Folder Management** and delete the folder.
5. Check the thumbnails directory again — **all thumbnail files from step 3 are still present**.
6. Repeat steps 1–5 — orphan files keep accumulating.

## Notes

- Each thumbnail is a JPEG up to 600×600px (typically 20–100 KB each).
- A user adding/removing 10 folders of 500 photos = ~5,000 orphaned thumbnails = ~100–500 MB leaked.
- Users have no way to identify or clean these orphaned files without manually inspecting the directory.
- This is related to but distinct from #569 (face data persistence) and #843 (thumbnail generation failure). Neither of those issues covers orphan thumbnail cleanup on folder deletion.

## Files Involved

- `backend/app/routes/folders.py` — `delete_folders()` (primary fix needed)
- `backend/app/utils/folders.py` — `folder_util_delete_obsolete_folders()` (also needs fix)
- `backend/app/database/images.py` — `db_get_images_by_folder_ids()` (needed to query thumbnails before deletion)
- `backend/app/utils/images.py` — `image_util_remove_obsolete_images()` (reference for correct thumbnail cleanup)

### Record

- [x] I agree to follow this project's Code of Conduct

### Record

- [x] I agree to follow this project's Code of Conduct

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.