@@ -277,6 +277,9 @@ export interface LocalStore {
277
277
executeQuery ( query : Query , usePreviousResults : boolean ) : Promise < QueryResult > ;
278
278
279
279
collectGarbage ( garbageCollector : LruGarbageCollector ) : Promise < LruResults > ;
280
+
281
+ /** Returns the serializer associated with the local store. */
282
+ getSerializer ( ) : JsonProtoSerializer ;
280
283
}
281
284
282
285
/**
@@ -1083,6 +1086,10 @@ class LocalStoreImpl implements LocalStore {
1083
1086
txn => garbageCollector . collect ( txn , this . targetDataByTarget )
1084
1087
) ;
1085
1088
}
1089
+
1090
+ getSerializer ( ) : JsonProtoSerializer {
1091
+ return this . serializer ;
1092
+ }
1086
1093
}
1087
1094
1088
1095
export function newLocalStore (
@@ -1249,30 +1256,6 @@ export async function ignoreIfPrimaryLeaseLoss(
1249
1256
}
1250
1257
}
1251
1258
1252
- export function getQueryDocumentMapping (
1253
- localStore : LocalStore ,
1254
- documents : BundledDocuments
1255
- ) : Map < string , DocumentKeySet > {
1256
- const localStoreImpl = debugCast ( localStore , LocalStoreImpl ) ;
1257
- const queryDocumentMap = new Map < string , DocumentKeySet > ( ) ;
1258
- const bundleConverter = new BundleConverter ( localStoreImpl . serializer ) ;
1259
- for ( const bundleDoc of documents ) {
1260
- if ( bundleDoc . metadata . queries ) {
1261
- const documentKey = bundleConverter . toDocumentKey (
1262
- bundleDoc . metadata . name !
1263
- ) ;
1264
- for ( const queryName of bundleDoc . metadata . queries ) {
1265
- const documentKeys = (
1266
- queryDocumentMap . get ( queryName ) || documentKeySet ( )
1267
- ) . add ( documentKey ) ;
1268
- queryDocumentMap . set ( queryName , documentKeys ) ;
1269
- }
1270
- }
1271
- }
1272
-
1273
- return queryDocumentMap ;
1274
- }
1275
-
1276
1259
/**
1277
1260
* Applies the documents from a bundle to the "ground-state" (remote)
1278
1261
* documents.
@@ -1324,9 +1307,6 @@ export function applyBundleDocuments(
1324
1307
txn ,
1325
1308
changedDocs
1326
1309
) ;
1327
- } )
1328
- . next ( changedDocuments => {
1329
- return PersistencePromise . resolve ( changedDocuments ) ;
1330
1310
} ) ;
1331
1311
}
1332
1312
) ;
@@ -1417,41 +1397,36 @@ export async function saveNamedQuery(
1417
1397
'readwrite' ,
1418
1398
transaction => {
1419
1399
// Update allocated target's read time, if the bundle's read time is newer.
1420
- let updateReadTime = PersistencePromise . resolve ( false ) ;
1400
+ let readTimeUpdated = PersistencePromise . resolve ( ) ;
1421
1401
const readTime = fromVersion ( query . readTime ! ) ;
1422
1402
if ( allocated . snapshotVersion . compareTo ( readTime ) < 0 ) {
1423
1403
const newTargetData = allocated . withResumeToken (
1424
1404
ByteString . EMPTY_BYTE_STRING ,
1425
1405
readTime
1426
1406
) ;
1427
- updateReadTime = localStoreImpl . targetCache
1407
+ readTimeUpdated = localStoreImpl . targetCache
1428
1408
. updateTargetData ( transaction , newTargetData )
1429
- . next (
1430
- ( ) => true ,
1431
- ( ) => false
1409
+ . next ( ( ) =>
1410
+ localStoreImpl . targetCache . removeMatchingKeysForTargetId (
1411
+ transaction ,
1412
+ allocated . targetId
1413
+ )
1414
+ )
1415
+ . next ( ( ) =>
1416
+ localStoreImpl . targetCache . addMatchingKeys (
1417
+ transaction ,
1418
+ documents ,
1419
+ allocated . targetId
1420
+ )
1432
1421
) ;
1433
1422
localStoreImpl . targetDataByTarget = localStoreImpl . targetDataByTarget . insert (
1434
1423
newTargetData . targetId ,
1435
1424
newTargetData
1436
1425
) ;
1437
1426
}
1438
- return updateReadTime
1439
- . next ( updated => {
1440
- if ( updated ) {
1441
- return localStoreImpl . targetCache
1442
- . removeMatchingKeysForTargetId ( transaction , allocated . targetId )
1443
- . next ( ( ) =>
1444
- localStoreImpl . targetCache . addMatchingKeys (
1445
- transaction ,
1446
- documents ,
1447
- allocated . targetId
1448
- )
1449
- ) ;
1450
- }
1451
- } )
1452
- . next ( ( ) =>
1453
- localStoreImpl . bundleCache . saveNamedQuery ( transaction , query )
1454
- ) ;
1427
+ return readTimeUpdated . next ( ( ) =>
1428
+ localStoreImpl . bundleCache . saveNamedQuery ( transaction , query )
1429
+ ) ;
1455
1430
}
1456
1431
) ;
1457
1432
}
0 commit comments