BUG: /folders/all-folders takes over a second when folders contain both images and videos
Maintainer thường phản hồi trong vòng 6 ngày
@Saurabhyadav0 đang làm issue này rồi.
Từ ngày 13/11/2026.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 75/100
Hướng nghiên cứu
Truy vấn chậm nằm trong db_get_all_folder_details() tại backend/app/database/folders.py, thực hiện LEFT JOIN bảng images và videos vào folders rồi đếm bằng COUNT(DISTINCT). Trước tiên, hãy đọc ba bình luận để kiểm tra xem đã có ai nhận việc này chưa. Viết lại hàm để đếm từng bảng trong một subquery GROUP BY folder_id riêng, rồi nối các tổng số đó vào folders. Hoàn thành khi phản hồi của /folders/all-folders không thay đổi với thư mục rỗng, chỉ có ảnh, chỉ có video và hỗn hợp, và một test mới trong các test thư mục hiện có khẳng định chính xác các số đếm đó.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Is there an existing issue for this?
- I have searched the existing issues
What happened?
db_get_all_folder_details() in backend/app/database/folders.py left-joins both images and videos onto folders on the same folder_id and uses COUNT(DISTINCT ...) to keep the counts right. The counts are correct, but SQLite still builds images × videos rows per folder before counting, so the cost grows with the product rather than the sum.
FROM folders f
LEFT JOIN images i ON f.folder_id = i.folder_id
LEFT JOIN videos v ON f.folder_id = v.folder_id
GROUP BY f.folder_id
While the folder list in Settings is open and a folder with AI tagging is still indexing, the frontend polls this endpoint every second (frontend/src/hooks/useFolderOperations.tsx), so on a large mixed library each poll takes over a second.
GET /folders/all-folders, median of 5, on a database built with the project's db_create_* functions:
| Library | Now |
|---|---|
| 20 folders × 2,500 images, no videos | 66 ms |
| 20 folders × 2,500 images × 10 videos | 144 ms |
| 20 folders × 2,500 images × 100 videos | 1,192 ms |
| 1 folder × 10,000 images × 500 videos | 1,184 ms |
Counting each table in its own GROUP BY folder_id subquery and joining the totals onto folders returns a byte-identical response in 3–20 ms for all of the above (also checked against empty, image-only and video-only folders). An index on folder_id alone doesn't help, since the row multiplication is the cost — with indexes added the current query actually got slower.
The query plan confirms the multiplication:
SCAN f ... | SEARCH i ... LEFT-JOIN | SEARCH v ... LEFT-JOIN
| USE TEMP B-TREE FOR count(DISTINCT) | USE TEMP B-TREE FOR count(DISTINCT)
Related: #876 reports the Settings folder list being slow in general. It predates this join (added in fab7ef08, 2026-07-24), so it isn't caused by it, but fixing this removes one source of that slowness. #1404 point 1 is what added video_count (the second join) — the counts it asked for are correct; this is about the cost only.
I'd like to work on this: rewrite the query to count each table in its own grouped subquery, and add a test with a folder holding several images and several videos (plus empty / image-only / video-only) asserting the exact counts are unchanged.
Record
- I agree to follow this project's Code of Conduct
- Ngôn ngữ chính
- Python
- Star
- 313
- Fork
- 755
- Merge trung bình
- 6 ngày 36 phút
- Pull request đã merge (30 ngày)
- 8
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của AOSSIE-Org/PictoPy
-
enhancement possible-duplicate
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 78/100
AOSSIE-Org/PictoPy#1715 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 6 ngày
-
Add unit tests for personUtils.tsCó thể đã có người làm @mystic-fae đã nhận hôm nay. Đang mởenhancement
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 62/100
AOSSIE-Org/PictoPy#1707 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 6 ngày
-
bug possible-duplicate
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
AOSSIE-Org/PictoPy#1702 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 6 ngày
-
bug possible-duplicate
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 86/100
AOSSIE-Org/PictoPy#1700 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 6 ngày
-
BUG: Share page returns HTTP 500 when the unlock cookie contains a non-ASCII characterCó thể làm lại được @swastiksharma45 đã nhận 7 ngày trước và không có pull request nào đang mở. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
AOSSIE-Org/PictoPy#1696 · 6 bình luận ·
Maintainer thường phản hồi trong vòng 6 ngày
Tất cả issue của AOSSIE-Org/PictoPy
Issue tương tự
-
README Quick Start query command fails, and doctor points to a missing Prerequisites sectionĐang mởdocumentation type/bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
add entry to blockĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 65/100
StevenBlack/hosts#3299 ·
-
`garak --report` overwrites the input report when its name has no ".report"Có thể đã có người làm @0z5a đã nhận hôm nay. Đang mởneeds-triage
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 2 ngày
-
trace: Pi's 1-hour cache writes are priced at 1.25x, but billed at 2xCó thể đã có người làm @Shizoqua đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
microsoft/TokenEconomizer#221 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
plot_graph crashes when a mesh node has no m2m edgeCó thể đã có người làm @tygvi đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
mllam/neural-lam#883 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày