fix(admin): three review findings — audit no-op, 404, chapter priority (0.41.1)
- admin_safe_set_is_admin: short-circuit when target.is_admin == value,
before writing audit. PATCH {is_admin: true} on someone already admin
previously wrote a misleading "promote_user" row even though the UPDATE
was a no-op.
- list_chapters (/admin/mangas/:id/chapters): explicit exists() check on
manga_id, returns 404 instead of 200 [] for a typo'd / deleted manga.
- ChapterSyncState priority: the Failed branch now requires page_count = 0,
so a chapter with pages on disk AND a historical dead job (from a
re-download attempt that crashed) stays Synced. The old order
contradicted Synced's documented "downloaded at some point" contract.
Doc comments updated alongside the SQL.
Three new regression tests pin the behaviour.
This commit is contained in:
@@ -13,8 +13,14 @@
|
||||
//! Priority order for `ChapterSyncState`:
|
||||
//! 1. `Downloading` — pending/running `sync_chapter_content` for this id
|
||||
//! 2. `Dropped` — chapter has source rows AND all are dropped
|
||||
//! 3. `Failed` — most recent terminal `sync_chapter_content` is `dead`
|
||||
//! 4. `NotDownloaded` — `page_count = 0`
|
||||
//! 3. `Failed` — `page_count = 0` AND a `dead` `sync_chapter_content`
|
||||
//! row exists for this chapter. Constrained to `page_count = 0`
|
||||
//! because once pages are on disk the chapter IS synced — a
|
||||
//! historical dead job (likely from a re-download attempt that
|
||||
//! crashed) is noise that gets reaped after retention. Surfacing
|
||||
//! "Failed" when content is present would contradict
|
||||
//! `ChapterSyncState::Synced`'s "downloaded at some point" contract.
|
||||
//! 4. `NotDownloaded` — `page_count = 0`, no in-flight, no dead job
|
||||
//! 5. `Synced` — `page_count > 0`
|
||||
//!
|
||||
//! Reminder: `done` jobs are reaped after `CRAWLER_JOB_RETENTION_DAYS`,
|
||||
@@ -181,7 +187,8 @@ pub async fn list_chapters_with_sync_state(
|
||||
WHERE cs.chapter_id = c.id AND cs.dropped_at IS NULL
|
||||
)
|
||||
THEN 'dropped'
|
||||
WHEN EXISTS (
|
||||
WHEN c.page_count = 0
|
||||
AND EXISTS (
|
||||
SELECT 1 FROM crawler_jobs cj
|
||||
WHERE cj.state = 'dead'
|
||||
AND cj.payload->>'kind' = 'sync_chapter_content'
|
||||
|
||||
Reference in New Issue
Block a user