fix(history): count distinct new chapter numbers, authoritative on detail
new_chapters_count over-counted when scanlations share a chapter number ((manga_id, number) is non-unique, migration 0013): COUNT(*) tallied rows, so duplicate-numbered chapters inflated the badge. Switch both the list and per-manga read-progress queries to COUNT(DISTINCT number), and drop the dead COALESCE (an empty set counts as 0, and the NULL-number case is handled by the predicate). Fix the misleading comment. Expose new_chapters_count on GET /me/read-progress/:manga_id and drive the detail page's "N new" badge from it, instead of recomputing over the paginated chapter list — which under-counted series past 50 chapters and disagreed with the homepage shelf. Read markers stay client-side over the loaded chapters and are documented as by-number (all we persist). Adds duplicate-scanlation tests at both endpoints. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -9,16 +9,21 @@ const ch1 = 'c1111111-1111-1111-1111-111111111111';
|
||||
const ch2 = 'c2222222-2222-2222-2222-222222222222';
|
||||
const ch3 = 'c3333333-3333-3333-3333-333333333333';
|
||||
|
||||
// Newest-first, as the API returns them.
|
||||
// Oldest-first, as repo::chapter::list_for_manga returns them.
|
||||
const chapters = [
|
||||
{ id: ch3, manga_id: mangaId, number: 3, title: null, page_count: 10, created_at: '2026-03-01T00:00:00Z' },
|
||||
{ id: ch1, manga_id: mangaId, number: 1, title: null, page_count: 8, created_at: '2026-01-01T00:00:00Z' },
|
||||
{ id: ch2, manga_id: mangaId, number: 2, title: null, page_count: 10, created_at: '2026-02-01T00:00:00Z' },
|
||||
{ id: ch1, manga_id: mangaId, number: 1, title: null, page_count: 8, created_at: '2026-01-01T00:00:00Z' }
|
||||
{ id: ch3, manga_id: mangaId, number: 3, title: null, page_count: 10, created_at: '2026-03-01T00:00:00Z' }
|
||||
];
|
||||
|
||||
async function mockDetail(
|
||||
page: Page,
|
||||
readProgress: { chapter_id: string; chapter_number: number; page: number } | null
|
||||
readProgress: {
|
||||
chapter_id: string;
|
||||
chapter_number: number;
|
||||
page: number;
|
||||
new_chapters_count: number;
|
||||
} | null
|
||||
) {
|
||||
await page.route('**/api/v1/auth/config', (r) =>
|
||||
r.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ self_register_enabled: true, private_mode: false }) })
|
||||
@@ -60,7 +65,8 @@ async function mockDetail(
|
||||
}
|
||||
|
||||
test('marks read chapters and counts new ones when mid-series', async ({ page }) => {
|
||||
await mockDetail(page, { chapter_id: ch1, chapter_number: 1, page: 1 });
|
||||
// Backend reports 2 distinct new chapters (2 and 3) past chapter 1.
|
||||
await mockDetail(page, { chapter_id: ch1, chapter_number: 1, page: 1, new_chapters_count: 2 });
|
||||
await page.goto(`/manga/${mangaId}`);
|
||||
|
||||
// Chapter 1 is read; 2 and 3 are not.
|
||||
|
||||
Reference in New Issue
Block a user