feat(history): report personal new-chapter count on read-progress list

Add `new_chapters_count` to each `GET /me/read-progress` item: how many
chapters sit past the reader's last-read chapter, computed by a correlated
subquery on chapter number. It is 0 when the reader is caught up, and 0
when the last-read chapter is unknown (manga-level progress or a deleted
chapter) so we never over-claim. (manga_id, number) is non-unique, so this
counts positions past the reader rather than distinct files.

Backs the personal "new since last read" indicator on the upcoming
Continue-reading shelf. Tests cover the mid-series, caught-up, and
no-read-chapter cases.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
MechaCat02
2026-07-04 20:50:20 +02:00
parent cf8971faae
commit f318c3bf51
7 changed files with 104 additions and 6 deletions

View File

@@ -132,7 +132,21 @@ pub async fn list_for_user(
rp.chapter_id,
c.number AS chapter_number,
rp.page,
rp.updated_at
rp.updated_at,
-- Personal "new since last read": chapters numbered past the
-- reader's last-read chapter. `c.number` is NULL for
-- manga-level progress or a deleted chapter, in which case
-- the guard yields 0 rather than counting every chapter.
-- (manga_id, number) is non-unique — translations share a
-- number — so this counts positions past the reader, not
-- distinct files.
COALESCE((
SELECT count(*)
FROM chapters c2
WHERE c2.manga_id = rp.manga_id
AND c.number IS NOT NULL
AND c2.number > c.number
), 0) AS new_chapters_count
FROM read_progress rp
JOIN mangas m ON m.id = rp.manga_id
LEFT JOIN chapters c ON c.id = rp.chapter_id