-
Notifications
You must be signed in to change notification settings - Fork 928
Marking SimpleDb calls as idempotent #2251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
schmidt-sebastian
merged 10 commits into
mrschmidt/idempotent
from
mrschmidt/simpleidempotent
Oct 10, 2019
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
48642ad
Add runTransaction parameter
schmidt-sebastian e4cdfe0
Add transaction retries
schmidt-sebastian d3669b6
Unit test fix
schmidt-sebastian 10c2f8e
[AUTOMATED]: Prettier Code Styling
schmidt-sebastian a1e5a00
First round of feedback
schmidt-sebastian aee20aa
Lint
schmidt-sebastian 3048923
Marking all SimpleDb calls as idempotent
schmidt-sebastian 9740f64
[AUTOMATED]: Prettier Code Styling
schmidt-sebastian 723de6d
Merge
schmidt-sebastian 8656142
Comments
schmidt-sebastian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -184,6 +184,7 @@ async function assertOrdered(paths: ResourcePath[]): Promise<void> { | |
|
||
const selected: string[] = []; | ||
await runTransaction(simpleStore => { | ||
selected.splice(0); // The function might get re-run. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would be cleaner if the selected array were just returned from the transaction. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's much cleaner. Updated. |
||
return simpleStore.iterate({ keysOnly: true }, key => { | ||
selected.push(key); | ||
}); | ||
|
@@ -216,7 +217,12 @@ function runTransaction<T>( | |
transaction: SimpleDbTransaction | ||
) => PersistencePromise<T> | ||
): Promise<T> { | ||
return db.runTransaction<T>('readwrite', ['test'], txn => { | ||
return fn(txn.store<string, boolean>('test'), txn); | ||
}); | ||
return db.runTransaction<T>( | ||
'readwrite-idempotent', | ||
['test'], | ||
txn => { | ||
return fn(txn.store<string, boolean>('test'), txn); | ||
} | ||
); | ||
|
||
} |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This appears to modify
this.listenSequence
in the transaction.Why not move that out of the transaction and into the first
then
block below?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a bunch of calls in the SDK that follow this pattern and re-compute a value inside a transaction, but the re-computation has no side effects. In this case, refactoring the change out of this transaction is pretty simple, so I applied the change. It might not always be so simple in other cases though.