File tree Expand file tree Collapse file tree 2 files changed +34
-12
lines changed Expand file tree Collapse file tree 2 files changed +34
-12
lines changed Original file line number Diff line number Diff line change @@ -226,22 +226,25 @@ export class LocalDocumentsView {
226
226
. next ( batches => {
227
227
for ( const batch of batches ) {
228
228
batch . keys ( ) . forEach ( key => {
229
- let mask : FieldMask | null = masks . has ( key )
230
- ? masks . get ( key ) !
231
- : FieldMask . empty ( ) ;
232
- mask = batch . applyToLocalView ( docs . get ( key ) ! , mask ) ;
233
- masks . set ( key , mask ) ;
234
- if ( documentsByBatchId . get ( batch . batchId ) === null ) {
229
+ const baseDoc = docs . get ( key ) ;
230
+ if ( baseDoc !== null ) {
231
+ let mask : FieldMask | null = masks . has ( key )
232
+ ? masks . get ( key ) !
233
+ : FieldMask . empty ( ) ;
234
+ mask = batch . applyToLocalView ( baseDoc , mask ) ;
235
+ masks . set ( key , mask ) ;
236
+ if ( documentsByBatchId . get ( batch . batchId ) === null ) {
237
+ documentsByBatchId = documentsByBatchId . insert (
238
+ batch . batchId ,
239
+ documentKeySet ( )
240
+ ) ;
241
+ }
242
+ const newSet = documentsByBatchId . get ( batch . batchId ) ! . add ( key ) ;
235
243
documentsByBatchId = documentsByBatchId . insert (
236
244
batch . batchId ,
237
- documentKeySet ( )
245
+ newSet
238
246
) ;
239
247
}
240
- const newSet = documentsByBatchId . get ( batch . batchId ) ! . add ( key ) ;
241
- documentsByBatchId = documentsByBatchId . insert (
242
- batch . batchId ,
243
- newSet
244
- ) ;
245
248
} ) ;
246
249
}
247
250
} )
Original file line number Diff line number Diff line change @@ -1801,6 +1801,25 @@ function genericLocalStoreTests(
1801
1801
) ;
1802
1802
} ) ;
1803
1803
1804
+ it ( 'can handle batch Ack when pending batches have other docs' , ( ) => {
1805
+ // Prepare two batches, the first one will get rejected by the backend.
1806
+ // When the first batch is rejected, overlay is recalculated with only the
1807
+ // second batch, even though it has more documents than what is being
1808
+ // rejected.
1809
+ return expectLocalStore ( )
1810
+ . afterMutations ( [ patchMutation ( 'foo/bar' , { 'foo' : 'bar' } ) ] )
1811
+ . afterMutations ( [
1812
+ setMutation ( 'foo/bar' , { 'foo' : 'bar-set' } ) ,
1813
+ setMutation ( 'foo/another' , { 'foo' : 'another' } )
1814
+ ] )
1815
+ . afterRejectingMutation ( )
1816
+ . toContain ( doc ( 'foo/bar' , 0 , { 'foo' : 'bar-set' } ) . setHasLocalMutations ( ) )
1817
+ . toContain (
1818
+ doc ( 'foo/another' , 0 , { 'foo' : 'another' } ) . setHasLocalMutations ( )
1819
+ )
1820
+ . finish ( ) ;
1821
+ } ) ;
1822
+
1804
1823
it ( 'uses target mapping to execute queries' , ( ) => {
1805
1824
if ( gcIsEager ) {
1806
1825
return ;
You can’t perform that action at this time.
0 commit comments