Repository navigation
Keep reader history saves from landing out of order - #119
Draft
PoonHarpoon wants to merge 1 commit into
Draft
PoonHarpoon wants to merge 1 commit into
PoonHarpoon wants to merge 1 commit into
Conversation
Each reader progress save runs as its own coroutine, and its transaction also rewrites chapters and updates tracking, so two saves requested milliseconds apart could reach the database in either order. A stale position (such as the one fixed in the previous commit) could then overwrite the correction made right after it and stay in history. Take a sequence number when a save is requested and skip writing any save older than one already written for that manga, so the newest request always wins.
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.
I’m currently testing this on my own device, and it’s opened as a draft so others can test it too before it’s marked ready. This goes together with #118, which fixes one source of bad saves; this one stops a bad save from sticking.
Each reader progress save (crossing into a new chapter, leaving the reader, going idle) runs as its own background task. Its database transaction also rewrites the chapter list and updates tracking. So two saves made a few milliseconds apart can reach the database in either order, and an out-of-date position can overwrite the newer one that came right after it. It’s the same kind of problem as the progress recalculation fix in #111, but for the reader’s own saves.
This adds a small HistorySaveOrder that numbers each save at the moment it’s requested. Saves are then written one at a time, and any save older than one already written for that manga is skipped, so the newest position always wins. A save that fails doesn’t count, so an older one can still go through. A skipped stale save also no longer triggers smart download for an out-of-date chapter. History changes you make yourself, like mark as read, mark as current and progress recalculation, aren’t affected.
HistorySaveOrderTest covers out-of-order saves, normal ordering, separate manga, a failed save, and two saves running at once. The full unit test suite passes.
The PR compiles and runs, but the bug is so transient and hard to reproduce on demand I’m still testing it on my end to see if this finally fixes it.