Repository navigation
Conversation
The scheduled task used FilterFilesType.Known, which skips any file whose size and mtime are unchanged regardless of whether it is still linked to an edition. When a book is deleted, BookDeletedEvent reaches MediaFileService, which calls UnlinkFilesByBook and leaves the BookFiles rows with EditionId = 0. Under Known those rows are never looked at again, because the file on disk has not changed, so the row's own existence is what prevents its repair. FilterFilesType.Matched already implements the right rule: skip only if unchanged and (matched or already remote-searched). RefreshAuthorService already scans with Matched; the scheduled task was the last caller on Known. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Database Migration
NO
Description
The scheduled task builds
RescanFoldersCommand()withFilter = FilterFilesType.Known.Knownskips any file whose size and mtime are unchanged, regardless of whether it isstill linked to an edition.
When a book is deleted — including by a metadata refresh —
BookDeletedEventreachesMediaFileService, which callsUnlinkFilesByBook; theBookFilesrows survive withEditionId = 0. UnderKnownthose rows are never looked at again, because the file ondisk has not changed. The row's own existence is what prevents its repair, so the library
cannot recover on its own — the only ways back are a manual unmapped-files import or
deleting rows by hand. 3,172 files were stranded this way on my library.
FilterFilesType.Matchedalready implements the right rule: skip only if unchangedand (matched or already remote-searched, per #183).
RefreshAuthorServicealreadypushes its rescan with
Matched; the scheduled task is the last caller still onKnown.This changes that default to match.
Evidence. A full-library scan on the stock default logs
Filtering 9812 files for unchanged files->Analyzing 0/9812 fileswhile 1,382BookFilesrows sit atEditionId = 0. That isKnownworking as designed: nothing on disk changed, so everyfile is excluded no matter how many are unlinked, and the unlinked ones can never come
back. A scan that does consider unlinked rows analyzed 252 of the same 9,812 and imported
113 files.
Cost, and a caveat on the marker this leans on.
Matchedskips an unchanged,unmatched file only once
LastRemoteSearchTimeis set, andIdentificationService.StampRemoteSearchResultsets it only whenEdition == null && RemoteSearchSucceeded. Two classes of file therefore never getstamped and are re-analyzed on every scheduled scan:
Has the same filesize as existing file,Not an upgrade for existing book file.Editionis non-null so nostamp is written, and
EditionIdstays 0 so they are never skipped. This is the largerclass on my library.
TryRemoteSearchcall — the Goodreads IDpath in
CandidateServiceis deliberately not routed through it, and there is an earlyyield breakwhen a file carries no usable author or title tag.On a 9,812-file library, 1,110 of 1,382 unlinked files are stamped and correctly skipped;
the remaining 272 are re-analyzed nightly, costing 5m24s per scan and importing nothing.
Bounded here, and it scales with the number of permanently unmatchable files rather than
with library size — but on a library with many of those it would be felt.
That marker is yours from #183 and I did not want to second-guess it inside a one-line
default change, so this PR leaves it alone. If you would rather stamp on any completed
identification attempt, or add a backoff, I am happy to do that here instead of — or as
well as — flipping the default.
Todos
RescanFoldersCommandFixture.FilterFixturealready covers theMatchedsemantics themselves (
filter_unmatched_should_return_existing_file_if_unmatched,added in don't keep searching if we didn't get a match #183)
Notes for reviewers
that is the point of the change, but it is a visible difference and may deserve a line
in release notes.
Issues Fixed or Closed by this PR
None. I looked for an existing report of this and did not find one.