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.
Save merging is when you override a save that hasn't been processed yet with a new one.
This fixes an edge case where we merge saves when it's not safe. For example, if you call save and then call close while the save is running
UpdateAsync
it would result in the document never being closed because the merge doesn't take affect since theUpdateAsync
call has already been made.Essentially it's always safe to merge saves unless
UpdateAsync
is running.This PR fixes this edge case by keeping track of
ongoingSaves
andpendingSaves
.ongoingSaves
are saves that have been added to the throttle queue.pendingSaves
are saves that are waiting for their respectiveongoingSave
to finish. We only merge pending saves now, we do not merge pending saves with ongoing saves. This means the merge algorithm is not completely optimal since it can be safe to merge saves even if they are in the throttle queue as long as they haven't calledUpdateAsync
. I plan to use the optimal algorithm eventually.