Repository navigation
Merged
Conversation
The use cases tested a 412 under two names with one body, cardsChangedElsewhere in cards.ts and raced in releaseDrafts.ts, and counted their tries with three constants that meant the same: the cards' CARD_EDIT_ATTEMPTS, the drafts' EDIT_ATTEMPTS and editDocument's own. A change to the policy had to be made in each. writes.ts now holds changedOrCreatedElsewhere, EDIT_ATTEMPTS for a document that changed since it was read, and PLACE_ATTEMPTS for a place taken elsewhere. editDocument takes EDIT_ATTEMPTS from there, which solid may import. The draft's name and the imported deck's id are the same kind of retry, so both use PLACE_ATTEMPTS: the import goes from two tries to three, as nothing said why it had one fewer. The digest's six tries and the upgrade's single try stay, each with its reason written beside it. Refs: #1086
Every loop that tries a write again on a 412 but the digest's tried at once. Two tabs or devices whose writes met once are then likely to meet again on the very next try, and lose all their tries together. pauseBefore in writes.ts waits a random time before each try again: up to 25 ms before the second, up to twice as long before each after, so a learner never notices it. editDocument waits it by default, and so do the use cases that plan a write again (a bulk edit of cards, a transfer, an edit of a draft), injected through createUseCases so their tests don't wait. The digest keeps its six tries and its growing wait, which outlasts another page writing it several times running, and adds the same random time on top, so no wait is shorter than before. Refs: #1086
…ite set A bulk edit of cards, a transfer of cards, a library upgrade and a deck file's import each wrote out the same loop by hand: plan from versioned reads, make and check every write, send them in a fixed order, and plan again on a 412. Each turned a version into a write condition its own way and recorded what was sent its own way, so a change to the policy had to be made in four places, and each tested its own 412 path. writeInOrder in writes.ts now runs that loop once. A plan gives its result and its writes in the order they are sent; the policy says how often it is planned again, on which failures, whether also once a write went out, and the pause before. It says how many writes were sent, and cutOffOf a failure says how far the set got. atVersion turns a read's version into a write condition. The bulk edit takes the defaults and tells of its changes once the cards are written. The transfer plans again also after writes were sent, as a card already in the target is not written again. The upgrade is tried once and takes whether the deck changed from what was sent, its steps still reported as each write is reached. The import plans again, at once, only when its deck's place is taken. Its entry stays the last write, and finishCutOffImport takes back what it wrote. editReleaseDraft keeps its own loop, which merges the try cut short. Nothing written to a pod changes. The policy is tested once, in writes.test.ts; each use case keeps the tests of its own rules. Closes: #1086
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.
What and why
A bulk edit of cards, a transfer of cards, a library upgrade and a deck file's import each wrote out the same loop by hand. Each one plans from versioned reads, makes and checks every write, sends them in a fixed order, and plans again on a 412. The retry counts had drifted, with nothing written down to say why: 3 in three places, 2 for the import, and two names for the same 412 test. Every loop except the digest's tried again at once, so two tabs or devices whose writes clashed once were likely to clash again on the next try.
Three commits:
One test and two counts (
writes.ts).changedOrCreatedElsewherereplacescardsChangedElsewhereandraced.EDIT_ATTEMPTS = 3is for a document that changed since it was read, andeditDocumentinsolidnow uses it too.PLACE_ATTEMPTS = 3is for a place taken elsewhere: a new draft's name, or an imported deck's id, which goes from 2 tries to 3. The digest's 6 tries and the upgrade's single try keep their reasons in a comment beside them.A random, growing pause before a 412 is tried again.
pauseBeforewaits up to 25 ms before the second try, and up to twice as long before each try after it, short enough that a learner never notices.editDocumentwaits it by default, and so do the use cases that plan again (the bulk edit, the transfer, a draft's edit);createUseCasesinjects it so their tests don't wait. The digest keeps its old growing wait as a minimum and adds the random part on top, so no wait is shorter than before.writeInOrderandatVersion. The bulk edit, transfer, upgrade and import now run the loop throughwriteInOrder, each with its own policy:cutOffOf), and still reports its steps.wholeAt,reviewsAtand the inline copy inlibrary.tsbecomeatVersion.A failed write set throws the error it failed with, unchanged, so the screens' messages stay as they are. A bulk edit or undo whose preview no longer fits the cards stops at once, as it does today, instead of planning again.
Nothing the app writes to a pod changes. The 412 policy is tested once, in
writes.test.ts. Each use case keeps the tests of its own rules, and the transfer gains a test that plans again after the target was written.docs/data-model.md(write discipline) anddocs/studio.mddescribe the new counts and the pause.One thing for review: one reviews document can be tried up to 12 times in a transfer. The adapter sends one If-Match PUT, then falls back to
editDocument's 3 tries, and the transfer plans again up to 3 times: 3 × (1 + 3). This branch doesn't change that. Counting the adapter's first PUT as its first try would bring it down to 9.npm run checkpasses on each commit.Closes: #1086