-
Notifications
You must be signed in to change notification settings - Fork 928
Port optimizations to LocalDocumentsView from iOS #1055
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
Merged
Changes from 16 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
65a53b2
wip
var-const f94e186
Local docs, path
var-const 64a293d
memory mutation queue, test left
var-const a969f3b
test fix
var-const 307a478
Fix iteration
var-const 2de3301
add test
var-const 5bf87ae
[AUTOMATED]: Prettier Code Styling
var-const 90a04cb
small fixes
var-const b94e7c7
appease linter
var-const 5b24623
Initial
var-const 49a261e
[AUTOMATED]: Prettier Code Styling
var-const 27c88eb
Merge branch 'varconst/silence-timestamp-warning-in-tests' into varco…
var-const 223c430
review feedback wip
var-const 42bf72b
Merge branch 'master' into varconst/port-affecting-batches
var-const c8375a6
Review feedback, indexeddb part
var-const 87e0b06
Review feedback, memory part
var-const 7082064
Merge branch 'master' into varconst/port-affecting-batches
var-const 0d068f5
Review fix
var-const 5dad79f
[AUTOMATED]: Prettier Code Styling
var-const ac1a01b
Merge branch 'master' into varconst/port-affecting-batches
var-const c40e50f
Merge branch 'varconst/port-affecting-batches' of github.com:firebase…
var-const e6cf4f5
Merge branch 'master' into varconst/port-affecting-batches
var-const 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 |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
import { Timestamp } from '../api/timestamp'; | ||
import { Query } from '../core/query'; | ||
import { BatchId, ProtoByteString } from '../core/types'; | ||
import { DocumentKeySet } from '../model/collections'; | ||
import { DocumentKey } from '../model/document_key'; | ||
import { Mutation } from '../model/mutation'; | ||
import { BATCHID_UNKNOWN, MutationBatch } from '../model/mutation_batch'; | ||
|
@@ -252,6 +253,27 @@ export class MemoryMutationQueue implements MutationQueue { | |
return PersistencePromise.resolve(result); | ||
} | ||
|
||
getAllMutationBatchesAffectingDocumentKeys( | ||
transaction: PersistenceTransaction, | ||
documentKeys: DocumentKeySet | ||
): PersistencePromise<MutationBatch[]> { | ||
let uniqueBatchIDs = new SortedSet<number>(primitiveComparator); | ||
|
||
documentKeys.forEach(documentKey => { | ||
const start = new DocReference(documentKey, 0); | ||
const end = new DocReference(documentKey, Number.POSITIVE_INFINITY); | ||
this.batchesByDocumentKey.forEachInRange([start, end], ref => { | ||
if (!documentKey.isEqual(ref.key)) { | ||
return; | ||
} | ||
|
||
uniqueBatchIDs = uniqueBatchIDs.add(ref.targetOrBatchId); | ||
}); | ||
}); | ||
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. Again, this is O(mutation queue) instead of O(document keys). Can we make it match iOS / Android? 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. PTAL. |
||
|
||
return PersistencePromise.resolve(this.findMutationBatches(uniqueBatchIDs)); | ||
} | ||
|
||
getAllMutationBatchesAffectingQuery( | ||
transaction: PersistenceTransaction, | ||
query: Query | ||
|
@@ -293,16 +315,20 @@ export class MemoryMutationQueue implements MutationQueue { | |
} | ||
}, start); | ||
|
||
return PersistencePromise.resolve(this.findMutationBatches(uniqueBatchIDs)); | ||
} | ||
|
||
private findMutationBatches(batchIDs: SortedSet<number>): MutationBatch[] { | ||
// Construct an array of matching batches, sorted by batchID to ensure that | ||
// multiple mutations affecting the same document key are applied in order. | ||
const result: MutationBatch[] = []; | ||
uniqueBatchIDs.forEach(batchId => { | ||
batchIDs.forEach(batchId => { | ||
const batch = this.findMutationBatch(batchId); | ||
if (batch !== null) { | ||
result.push(batch); | ||
} | ||
}); | ||
return PersistencePromise.resolve(result); | ||
return result; | ||
} | ||
|
||
removeMutationBatches( | ||
|
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.
nit: Is it possible to hit this? Seems like our range should constrain us to
documentKey
.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.
I'm not sure. This function is derived from
getAllMutationBatchesAffectingDocumentKey
, which asserts this equality, this led me to believe this case is not impossible. I can remove it altogether or replace with an assertion.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.
Asserts should generally mean the case is impossible. They exist to document our expectations and/or catch false expectations as early as possible to make finding / fixing bugs later. So I think an assert here makes perfect sense.
Fine print: We're probably not 100% rigorous about asserts always being impossible. E.g. there may be cases where we use asserts for cases that /are/ possible but represent rare error conditions that we don't feel compelled to provide proper error handling for.
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.
Replicated the assertion.