Repository navigation
fix(reader): refresh a cached page list that no longer matches the book - #1340
Conversation
The reader keeps each book's page list, with page sizes, in the local database and reuses it on later opens, refreshing it from the server only when a page lacks dimensions. When the book's file changes on the server and Komga analyzes it again, the cached list stays as it was. Page images are still requested by number, so they come from the new analysis while their sizes and the page count come from the old one. A file that gained a page early on shifts every later page by one: a portrait page takes the size of the spread after it and opens as a spread, a spread takes the size of the portrait page after it and opens as a single page, and the reader shows one page fewer than the book has. A cached list now also counts as stale when its length differs from the book's page count, which the reader syncs from the server before loading pages, and is refreshed then. Komga sets that count to the length of the page list for every format the image reader opens. A downloaded book keeps its cached list, since it describes the downloaded files the reader shows. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
everpcpc
left a comment
There was a problem hiding this comment.
The count-based refresh is a good minimal way to repair stale page metadata, and the offline/downloaded handling looks consistent. However, the image-cache path still needs invalidation for renumbered replacement files; otherwise the reader can combine new page metadata with old cached images. I have left a blocking inline comment with a concrete example and the suggested invalidation scope.
…pages A refresh triggered by the page-count check replaced the cached page list but kept the book's cached page images, and filled sizes missing from the server's list from the cached list by file name. The image cache is keyed by page number and file name, and a renumbered file reuses both for other images: after 001=A, 002=B became 001=X, 002=A, the refreshed page 2 still showed the cached B. A size carried over by file name can likewise belong to another image. When the book has changed, the refresh now clears the book's page-image cache and takes the server's page list as is. The refresh for missing dimensions still keeps known sizes and cached images, and downloaded books are still exempt. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The failing iOS check isn't from this change. The cause is the simulator selection in If you'd like to rule this out: a build needs no concrete device, so if normalized in ("ios", "tvos"):
if ci_mode:
destination = self._generic_simulator_destination(normalized)
else:
... # existing select_device logicAlternatively, 🤖 Generated with Claude Code |
everpcpc
left a comment
There was a problem hiding this comment.
The update resolves the blocking cache-coherence issue. Count-mismatch refreshes now clear the book’s cached images and no longer carry over dimensions by file name, while missing-dimensions refreshes and downloaded books retain their previous behavior. The positional-name validation covers the reported counterexample, including both adding and removing a page. I have no further code findings. The remaining iOS check failure appears to be the documented simulator-destination issue rather than a code failure; please rerun it before merge.
Closes #1339
Problem
When a book's file is replaced on the server with a version that has one more page, the reader keeps the page list it cached before. Page images are requested by number and come from the new file, while their sizes and the page count come from the old list. From the added page on, each page gets the size of the page after it: a spread opens as a single page, a portrait page opens as a spread, and the counter shows one page fewer. Details in #1339.
Root cause
ReaderContentService.loadPages(for:)andfetchSegmentPages(for:…)use the cachedKomgaBook.pageswhenever it exists, and refresh it from the server only when a page lacks dimensions.applyBook(dto:to:)) updates itsmedia, includingpagesCount, but leaves the cached page list alone./api/v1/books/{id}/pages/{n}), which Komga resolves against its current analysis of the file.Fix
media.pagesCount(cachedPagesMatch(_:book:)).CacheManager.clearCache(forBookId:)) and takes the server's list as is.resolvePageDimensionsis renamedresolvePages(for:…), and the refresh moves intorefreshedCachedPages(_:for:).Why this shape
Not changed
Validation
make build-ios,make build-macos-ci,make build-tvos-ci).001.png–004.png= A, B, C (spread), D, renumbered to001.png–005.png= X, A, B, C (spread), D.main:page/N/00N.png. Then I replaced it with v2 (deep scan) and reopened:🤖 Generated with Claude Code