@@ -200,10 +200,13 @@ export class LocalStore {
200
200
*/
201
201
// PORTING NOTE: Android and iOS only return the documents affected by the
202
202
// change.
203
- handleUserChange ( user : User ) : Promise < UserChangeResult > {
204
- return this . persistence . runTransaction (
203
+ async handleUserChange ( user : User ) : Promise < UserChangeResult > {
204
+ let newMutationQueue = this . mutationQueue ;
205
+ let newLocalDocuments = this . localDocuments ;
206
+
207
+ const result = await this . persistence . runTransaction (
205
208
'Handle user change' ,
206
- 'readonly' ,
209
+ 'readonly-idempotent ' ,
207
210
txn => {
208
211
// Swap out the mutation queue, grabbing the pending mutation batches
209
212
// before and after.
@@ -213,17 +216,16 @@ export class LocalStore {
213
216
. next ( promisedOldBatches => {
214
217
oldBatches = promisedOldBatches ;
215
218
216
- this . mutationQueue = this . persistence . getMutationQueue ( user ) ;
219
+ newMutationQueue = this . persistence . getMutationQueue ( user ) ;
217
220
218
221
// Recreate our LocalDocumentsView using the new
219
222
// MutationQueue.
220
- this . localDocuments = new LocalDocumentsView (
223
+ newLocalDocuments = new LocalDocumentsView (
221
224
this . remoteDocuments ,
222
- this . mutationQueue ,
225
+ newMutationQueue ,
223
226
this . persistence . getIndexManager ( )
224
227
) ;
225
- this . queryEngine . setLocalDocumentsView ( this . localDocuments ) ;
226
- return this . mutationQueue . getAllMutationBatches ( txn ) ;
228
+ return newMutationQueue . getAllMutationBatches ( txn ) ;
227
229
} )
228
230
. next ( newBatches => {
229
231
const removedBatchIds : BatchId [ ] = [ ] ;
@@ -248,7 +250,7 @@ export class LocalStore {
248
250
249
251
// Return the set of all (potentially) changed documents and the list
250
252
// of mutation batch IDs that were affected by change.
251
- return this . localDocuments
253
+ return newLocalDocuments
252
254
. getDocuments ( txn , changedKeys )
253
255
. next ( affectedDocuments => {
254
256
return {
@@ -260,7 +262,14 @@ export class LocalStore {
260
262
} ) ;
261
263
}
262
264
) ;
265
+
266
+ this . mutationQueue = newMutationQueue ;
267
+ this . localDocuments = newLocalDocuments ;
268
+ this . queryEngine . setLocalDocumentsView ( this . localDocuments ) ;
269
+
270
+ return result ;
263
271
}
272
+
264
273
/* Accept locally generated Mutations and commit them to storage. */
265
274
localWrite ( mutations : Mutation [ ] ) : Promise < LocalWriteResult > {
266
275
const localWriteTime = Timestamp . now ( ) ;
0 commit comments