Skip to content

Commit a9f8a8f

Browse files
authored
Migrate FSTBatchID to C++ BatchId (#1700)
1 parent 97c499c commit a9f8a8f

36 files changed

+103
-106
lines changed

Firestore/Example/Benchmarks/FSTLevelDBBenchmarkTests.mm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
#include "benchmark/benchmark.h"
2222

23-
#import "Firestore/Source/Core/FSTTypes.h"
2423
#import "Firestore/Source/Local/FSTLevelDB.h"
2524
#import "Firestore/Source/Local/FSTLocalSerializer.h"
2625
#import "Firestore/Source/Model/FSTDocumentKey.h"

Firestore/Example/Tests/Integration/FSTDatastoreTests.mm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
namespace util = firebase::firestore::util;
4848
using firebase::firestore::auth::EmptyCredentialsProvider;
4949
using firebase::firestore::core::DatabaseInfo;
50+
using firebase::firestore::model::BatchId;
5051
using firebase::firestore::model::DatabaseId;
5152
using firebase::firestore::model::DocumentKeySet;
5253
using firebase::firestore::model::Precondition;
@@ -118,7 +119,7 @@ - (void)applySuccessfulWriteWithResult:(FSTMutationBatchResult *)batchResult {
118119
[expectation fulfill];
119120
}
120121

121-
- (void)rejectFailedWriteWithBatchID:(FSTBatchID)batchID error:(NSError *)error {
122+
- (void)rejectFailedWriteWithBatchID:(BatchId)batchID error:(NSError *)error {
122123
HARD_FAIL("Not implemented");
123124
}
124125

Firestore/Example/Tests/Local/FSTLRUGarbageCollectorTests.mm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include <unordered_set>
2222

2323
#import "Firestore/Example/Tests/Util/FSTHelpers.h"
24-
#import "Firestore/Source/Core/FSTTypes.h"
2524
#import "Firestore/Source/Local/FSTLRUGarbageCollector.h"
2625
#import "Firestore/Source/Local/FSTMutationQueue.h"
2726
#import "Firestore/Source/Local/FSTPersistence.h"

Firestore/Example/Tests/Local/FSTLevelDBMigrationsTests.mm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
using firebase::firestore::local::LevelDbTargetDocumentKey;
4646
using firebase::firestore::local::LevelDbTargetKey;
4747
using firebase::firestore::local::LevelDbTransaction;
48+
using firebase::firestore::model::BatchId;
4849
using firebase::firestore::model::TargetId;
4950
using firebase::firestore::testutil::Key;
5051
using firebase::firestore::util::OrderedCode;
@@ -119,7 +120,7 @@ - (void)testSetsVersionNumber {
119120

120121
- (void)testDropsTheQueryCache {
121122
std::string userID{"user"};
122-
FSTBatchID batchID = 1;
123+
BatchId batchID = 1;
123124
TargetId targetID = 2;
124125

125126
FSTDocumentKey *key1 = Key("documents/1");

Firestore/Example/Tests/Local/FSTLevelDBMutationQueueTests.mm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
using firebase::firestore::auth::User;
3838
using firebase::firestore::local::LevelDbMutationKey;
39+
using firebase::firestore::model::BatchId;
3940
using firebase::firestore::util::OrderedCode;
4041
using leveldb::DB;
4142
using leveldb::Slice;
@@ -57,7 +58,7 @@ @interface FSTLevelDBMutationQueueTests : FSTMutationQueueTests
5758
* Creates a key that's structurally the same as LevelDbMutationKey except it allows for
5859
* nonstandard table names.
5960
*/
60-
std::string MutationLikeKey(absl::string_view table, absl::string_view userID, FSTBatchID batchID) {
61+
std::string MutationLikeKey(absl::string_view table, absl::string_view userID, BatchId batchID) {
6162
std::string key;
6263
OrderedCode::WriteString(&key, table);
6364
OrderedCode::WriteString(&key, userID);
@@ -119,7 +120,7 @@ - (void)testLoadNextBatchID_findsMaxAcrossUsers {
119120
- (void)testLoadNextBatchID_onlyFindsMutations {
120121
// Write higher-valued batchIDs in nearby "tables"
121122
std::vector<std::string> tables{"mutatio", "mutationsa", "bears", "zombies"};
122-
FSTBatchID highBatchID = 5;
123+
BatchId highBatchID = 5;
123124
for (const auto &table : tables) {
124125
[self setDummyValueForKey:MutationLikeKey(table, "", highBatchID++)];
125126
}

Firestore/Example/Tests/Remote/FSTWatchChange+Testing.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
#import <Foundation/Foundation.h>
1818

19-
#import "Firestore/Source/Core/FSTTypes.h"
2019
#import "Firestore/Source/Remote/FSTWatchChange.h"
2120

2221
NS_ASSUME_NONNULL_BEGIN

Firestore/Example/Tests/SpecTests/FSTSyncEngineTestDriver.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include <map>
2020
#include <unordered_map>
2121

22-
#import "Firestore/Source/Core/FSTTypes.h"
2322
#import "Firestore/Source/Remote/FSTRemoteStore.h"
2423
#import "Firestore/Source/Util/FSTDispatchQueue.h"
2524

Firestore/Example/Tests/Util/FSTHelpers.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include <string>
2020
#include <vector>
2121

22-
#import "Firestore/Source/Core/FSTTypes.h"
2322
#import "Firestore/Source/Model/FSTDocumentDictionary.h"
2423
#import "Firestore/Source/Remote/FSTRemoteEvent.h"
2524

Firestore/Example/Tests/Util/FSTIntegrationTestCase.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#import <XCTest/XCTest.h>
1919

2020
#import "Firestore/Example/Tests/Util/XCTestCase+Await.h"
21-
#import "Firestore/Source/Core/FSTTypes.h"
2221

2322
#import "FIRFirestoreSource.h"
2423

Firestore/Source/Core/FSTEventManager.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
#import <Foundation/Foundation.h>
1818

19-
#import "Firestore/Source/Core/FSTTypes.h"
2019
#import "Firestore/Source/Core/FSTViewSnapshot.h"
2120
#import "Firestore/Source/Remote/FSTRemoteStore.h"
2221

Firestore/Source/Core/FSTFirestoreClient.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#import <Foundation/Foundation.h>
1818
#include <memory>
1919

20-
#import "Firestore/Source/Core/FSTTypes.h"
2120
#import "Firestore/Source/Core/FSTViewSnapshot.h"
2221
#import "Firestore/Source/Remote/FSTRemoteStore.h"
2322

Firestore/Source/Core/FSTListenSequence.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
#import <Foundation/Foundation.h>
1818

19-
#import "FSTTypes.h"
19+
#import "Firestore/Source/Core/FSTTypes.h"
2020

2121
NS_ASSUME_NONNULL_BEGIN
2222

Firestore/Source/Core/FSTSyncEngine.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
#import <Foundation/Foundation.h>
1818

19-
#import "Firestore/Source/Core/FSTTypes.h"
2019
#import "Firestore/Source/Remote/FSTRemoteStore.h"
2120

2221
#include "Firestore/core/src/firebase/firestore/auth/user.h"

Firestore/Source/Core/FSTSyncEngine.mm

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
using firebase::firestore::auth::HashUser;
5050
using firebase::firestore::auth::User;
5151
using firebase::firestore::core::TargetIdGenerator;
52+
using firebase::firestore::model::BatchId;
5253
using firebase::firestore::model::DocumentKey;
5354
using firebase::firestore::model::DocumentKeySet;
5455
using firebase::firestore::model::SnapshotVersion;
@@ -162,7 +163,7 @@ @implementation FSTSyncEngine {
162163
/** Used for creating the TargetId for the listens used to resolve limbo documents. */
163164
TargetIdGenerator _targetIdGenerator;
164165

165-
/** Stores user completion blocks, indexed by user and FSTBatchID. */
166+
/** Stores user completion blocks, indexed by user and BatchId. */
166167
std::unordered_map<User, NSMutableDictionary<NSNumber *, FSTVoidErrorBlock> *, HashUser>
167168
_mutationCompletionBlocks;
168169

@@ -246,7 +247,7 @@ - (void)writeMutations:(NSArray<FSTMutation *> *)mutations
246247
[self.remoteStore fillWritePipeline];
247248
}
248249

249-
- (void)addMutationCompletionBlock:(FSTVoidErrorBlock)completion batchID:(FSTBatchID)batchID {
250+
- (void)addMutationCompletionBlock:(FSTVoidErrorBlock)completion batchID:(BatchId)batchID {
250251
NSMutableDictionary<NSNumber *, FSTVoidErrorBlock> *completionBlocks =
251252
_mutationCompletionBlocks[_currentUser];
252253
if (!completionBlocks) {
@@ -407,7 +408,7 @@ - (void)applySuccessfulWriteWithResult:(FSTMutationBatchResult *)batchResult {
407408
[self emitNewSnapshotsWithChanges:changes remoteEvent:nil];
408409
}
409410

410-
- (void)rejectFailedWriteWithBatchID:(FSTBatchID)batchID error:(NSError *)error {
411+
- (void)rejectFailedWriteWithBatchID:(BatchId)batchID error:(NSError *)error {
411412
[self assertDelegateExistsForSelector:_cmd];
412413

413414
// The local store may or may not be able to apply the write result and raise events immediately
@@ -419,7 +420,7 @@ - (void)rejectFailedWriteWithBatchID:(FSTBatchID)batchID error:(NSError *)error
419420
[self emitNewSnapshotsWithChanges:changes remoteEvent:nil];
420421
}
421422

422-
- (void)processUserCallbacksForBatchID:(FSTBatchID)batchID error:(NSError *_Nullable)error {
423+
- (void)processUserCallbacksForBatchID:(BatchId)batchID error:(NSError *_Nullable)error {
423424
NSMutableDictionary<NSNumber *, FSTVoidErrorBlock> *completionBlocks =
424425
_mutationCompletionBlocks[_currentUser];
425426

Firestore/Source/Core/FSTTypes.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,8 @@ NS_ASSUME_NONNULL_BEGIN
2323
@class FSTMaybeDocument;
2424
@class FSTTransaction;
2525

26-
/** FSTBatchID is a locally assigned ID for a batch of mutations that have been applied. */
27-
typedef firebase::firestore::model::BatchId FSTBatchID;
28-
2926
typedef int64_t FSTListenSequenceNumber;
3027

31-
typedef NSNumber FSTBoxedTargetID;
32-
3328
/**
3429
* FSTVoidBlock is a block that's called when a specific event happens but that otherwise has
3530
* no information associated with it.

Firestore/Source/Local/FSTDocumentReference.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ NS_ASSUME_NONNULL_BEGIN
2626
* and a document key that the target or batch references.
2727
*
2828
* A reference can be from either listen targets (identified by their TargetId) or mutation batches
29-
* (identified by their FSTBatchID). See FSTGarbageCollector for more details.
29+
* (identified by their BatchId). See FSTGarbageCollector for more details.
3030
*
3131
* Not to be confused with FIRDocumentReference.
3232
*/

Firestore/Source/Local/FSTLRUGarbageCollector.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
#import <Foundation/Foundation.h>
1818

19-
#import "Firestore/Source/Core/FSTTypes.h"
2019
#import "Firestore/Source/Local/FSTQueryData.h"
2120
#include "Firestore/core/src/firebase/firestore/model/document_key.h"
2221

@@ -97,4 +96,4 @@ extern const FSTListenSequenceNumber kFSTListenSequenceNumberInvalid;
9796
*/
9897
- (int)removeOrphanedDocumentsThroughSequenceNumber:(FSTListenSequenceNumber)sequenceNumber;
9998

100-
@end
99+
@end

Firestore/Source/Local/FSTLRUGarbageCollector.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,4 @@ - (int)removeOrphanedDocumentsThroughSequenceNumber:(FSTListenSequenceNumber)seq
118118
return [_delegate removeOrphanedDocumentsThroughSequenceNumber:sequenceNumber];
119119
}
120120

121-
@end
121+
@end

Firestore/Source/Local/FSTLevelDBMutationQueue.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#import "Firestore/Source/Local/FSTMutationQueue.h"
2222

2323
#include "Firestore/core/src/firebase/firestore/auth/user.h"
24+
#include "Firestore/core/src/firebase/firestore/model/types.h"
2425
#include "leveldb/db.h"
2526

2627
@class FSTLevelDB;
@@ -47,7 +48,7 @@ NS_ASSUME_NONNULL_BEGIN
4748
* Returns one larger than the largest batch ID that has been stored. If there are no mutations
4849
* returns 0. Note that batch IDs are global.
4950
*/
50-
+ (FSTBatchID)loadNextBatchIDFromDB:(leveldb::DB *)db;
51+
+ (firebase::firestore::model::BatchId)loadNextBatchIDFromDB:(leveldb::DB *)db;
5152

5253
@end
5354

0 commit comments

Comments
 (0)