Files
firebase-ios-sdk/Firestore/Example/Tests/Local/FSTMutationQueueTests.mm
T

444 lines
15 KiB
Plaintext
Raw Normal View History

2017-10-03 08:55:22 -07:00
/*
* Copyright 2017 Google
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#import "Firestore/Example/Tests/Local/FSTMutationQueueTests.h"
2017-10-03 08:55:22 -07:00
#import <FirebaseFirestore/FIRTimestamp.h>
#include <set>
2019-02-07 22:03:17 -05:00
#include <utility>
2019-01-28 10:21:20 -08:00
#include <vector>
#import "Firestore/Source/Core/FSTQuery.h"
#import "Firestore/Source/Local/FSTPersistence.h"
#import "Firestore/Source/Model/FSTMutation.h"
#import "Firestore/Source/Model/FSTMutationBatch.h"
2017-10-03 08:55:22 -07:00
#import "Firestore/Example/Tests/Util/FSTHelpers.h"
2017-10-03 08:55:22 -07:00
#include "Firestore/core/src/firebase/firestore/auth/user.h"
2018-03-23 17:52:01 -04:00
#include "Firestore/core/src/firebase/firestore/model/document_key.h"
#include "Firestore/core/src/firebase/firestore/model/document_key_set.h"
#include "Firestore/core/src/firebase/firestore/model/mutation_batch.h"
2018-03-23 17:52:01 -04:00
#include "Firestore/core/test/firebase/firestore/testutil/testutil.h"
2018-03-23 17:52:01 -04:00
namespace testutil = firebase::firestore::testutil;
using firebase::firestore::auth::User;
2018-03-23 17:52:01 -04:00
using firebase::firestore::model::DocumentKey;
using firebase::firestore::model::DocumentKeySet;
using firebase::firestore::model::kBatchIdUnknown;
using firebase::firestore::testutil::Key;
2017-10-03 08:55:22 -07:00
NS_ASSUME_NONNULL_BEGIN
@implementation FSTMutationQueueTests
- (void)tearDown {
[self.persistence shutdown];
[super tearDown];
}
/**
* Xcode will run tests from any class that extends XCTestCase, but this doesn't work for
* FSTMutationQueueTests since it is incomplete without the implementations supplied by its
* subclasses.
*/
- (BOOL)isTestBaseClass {
return [self class] == [FSTMutationQueueTests class];
}
- (void)testCountBatches {
if ([self isTestBaseClass]) return;
2018-03-30 10:18:25 -07:00
self.persistence.run("testCountBatches", [&]() {
XCTAssertEqual(0, [self batchCount]);
2019-01-28 10:21:20 -08:00
XCTAssertTrue(self.mutationQueue->IsEmpty());
2017-10-03 08:55:22 -07:00
2018-03-30 10:18:25 -07:00
FSTMutationBatch *batch1 = [self addMutationBatch];
XCTAssertEqual(1, [self batchCount]);
2019-01-28 10:21:20 -08:00
XCTAssertFalse(self.mutationQueue->IsEmpty());
2017-10-03 08:55:22 -07:00
2018-03-30 10:18:25 -07:00
FSTMutationBatch *batch2 = [self addMutationBatch];
XCTAssertEqual(2, [self batchCount]);
2017-10-03 08:55:22 -07:00
2019-01-28 10:21:20 -08:00
self.mutationQueue->RemoveMutationBatch(batch1);
2018-03-30 10:18:25 -07:00
XCTAssertEqual(1, [self batchCount]);
2017-10-03 08:55:22 -07:00
2019-01-28 10:21:20 -08:00
self.mutationQueue->RemoveMutationBatch(batch2);
2018-03-30 10:18:25 -07:00
XCTAssertEqual(0, [self batchCount]);
2019-01-28 10:21:20 -08:00
XCTAssertTrue(self.mutationQueue->IsEmpty());
2018-03-30 10:18:25 -07:00
});
2017-10-03 08:55:22 -07:00
}
- (void)testAcknowledgeBatchID {
if ([self isTestBaseClass]) return;
2018-03-30 10:18:25 -07:00
self.persistence.run("testAcknowledgeBatchID", [&]() {
XCTAssertEqual([self batchCount], 0);
2018-03-30 10:18:25 -07:00
FSTMutationBatch *batch1 = [self addMutationBatch];
FSTMutationBatch *batch2 = [self addMutationBatch];
FSTMutationBatch *batch3 = [self addMutationBatch];
XCTAssertGreaterThan(batch1.batchID, kBatchIdUnknown);
2018-03-30 10:18:25 -07:00
XCTAssertGreaterThan(batch2.batchID, batch1.batchID);
XCTAssertGreaterThan(batch3.batchID, batch2.batchID);
2017-10-03 08:55:22 -07:00
XCTAssertEqual([self batchCount], 3);
2017-10-03 08:55:22 -07:00
2019-01-28 10:21:20 -08:00
self.mutationQueue->AcknowledgeBatch(batch1, nil);
self.mutationQueue->RemoveMutationBatch(batch1);
XCTAssertEqual([self batchCount], 2);
2018-11-06 14:24:06 -08:00
2019-01-28 10:21:20 -08:00
self.mutationQueue->AcknowledgeBatch(batch2, nil);
XCTAssertEqual([self batchCount], 2);
2017-10-03 08:55:22 -07:00
2019-01-28 10:21:20 -08:00
self.mutationQueue->RemoveMutationBatch(batch2);
XCTAssertEqual([self batchCount], 1);
2017-10-03 08:55:22 -07:00
2019-01-28 10:21:20 -08:00
self.mutationQueue->RemoveMutationBatch(batch3);
XCTAssertEqual([self batchCount], 0);
2018-03-30 10:18:25 -07:00
});
2017-10-03 08:55:22 -07:00
}
- (void)testAcknowledgeThenRemove {
if ([self isTestBaseClass]) return;
2018-03-30 10:18:25 -07:00
self.persistence.run("testAcknowledgeThenRemove", [&]() {
FSTMutationBatch *batch1 = [self addMutationBatch];
2017-10-03 08:55:22 -07:00
2019-01-28 10:21:20 -08:00
self.mutationQueue->AcknowledgeBatch(batch1, nil);
self.mutationQueue->RemoveMutationBatch(batch1);
2017-10-03 08:55:22 -07:00
2018-03-30 10:18:25 -07:00
XCTAssertEqual([self batchCount], 0);
});
2017-10-03 08:55:22 -07:00
}
- (void)testLookupMutationBatch {
if ([self isTestBaseClass]) return;
// Searching on an empty queue should not find a non-existent batch
2018-03-30 10:18:25 -07:00
self.persistence.run("testLookupMutationBatch", [&]() {
2019-01-28 10:21:20 -08:00
FSTMutationBatch *notFound = self.mutationQueue->LookupMutationBatch(42);
2017-10-03 08:55:22 -07:00
XCTAssertNil(notFound);
2019-01-28 10:21:20 -08:00
std::vector<FSTMutationBatch *> batches = [self createBatches:10];
std::vector<FSTMutationBatch *> removed = [self removeFirstBatches:3 inBatches:&batches];
2017-10-03 08:55:22 -07:00
2018-03-30 10:18:25 -07:00
// After removing, a batch should not be found
2019-01-28 10:21:20 -08:00
for (size_t i = 0; i < removed.size(); i++) {
notFound = self.mutationQueue->LookupMutationBatch(removed[i].batchID);
2018-03-30 10:18:25 -07:00
XCTAssertNil(notFound);
}
// Remaining entries should still be found
2019-01-28 10:21:20 -08:00
for (FSTMutationBatch *batch : batches) {
FSTMutationBatch *found = self.mutationQueue->LookupMutationBatch(batch.batchID);
2018-03-30 10:18:25 -07:00
XCTAssertEqual(found.batchID, batch.batchID);
}
// Even on a nonempty queue searching should not find a non-existent batch
2019-01-28 10:21:20 -08:00
notFound = self.mutationQueue->LookupMutationBatch(42);
2018-03-30 10:18:25 -07:00
XCTAssertNil(notFound);
});
2017-10-03 08:55:22 -07:00
}
- (void)testNextMutationBatchAfterBatchID {
if ([self isTestBaseClass]) return;
2018-03-30 10:18:25 -07:00
self.persistence.run("testNextMutationBatchAfterBatchID", [&]() {
2019-01-28 10:21:20 -08:00
std::vector<FSTMutationBatch *> batches = [self createBatches:10];
std::vector<FSTMutationBatch *> removed = [self removeFirstBatches:3 inBatches:&batches];
2017-10-03 08:55:22 -07:00
2019-01-28 10:21:20 -08:00
for (size_t i = 0; i < batches.size() - 1; i++) {
2018-03-30 10:18:25 -07:00
FSTMutationBatch *current = batches[i];
FSTMutationBatch *next = batches[i + 1];
2019-01-28 10:21:20 -08:00
FSTMutationBatch *found = self.mutationQueue->NextMutationBatchAfterBatchId(current.batchID);
2018-03-30 10:18:25 -07:00
XCTAssertEqual(found.batchID, next.batchID);
}
2017-10-03 08:55:22 -07:00
2019-01-28 10:21:20 -08:00
for (size_t i = 0; i < removed.size(); i++) {
2018-03-30 10:18:25 -07:00
FSTMutationBatch *current = removed[i];
2018-11-06 14:24:06 -08:00
FSTMutationBatch *next = batches[0];
2019-01-28 10:21:20 -08:00
FSTMutationBatch *found = self.mutationQueue->NextMutationBatchAfterBatchId(current.batchID);
2018-03-30 10:18:25 -07:00
XCTAssertEqual(found.batchID, next.batchID);
}
2017-10-03 08:55:22 -07:00
2018-03-30 10:18:25 -07:00
FSTMutationBatch *first = batches[0];
2019-01-28 10:21:20 -08:00
FSTMutationBatch *found = self.mutationQueue->NextMutationBatchAfterBatchId(first.batchID - 42);
2018-03-30 10:18:25 -07:00
XCTAssertEqual(found.batchID, first.batchID);
2017-10-03 08:55:22 -07:00
2019-01-28 10:21:20 -08:00
FSTMutationBatch *last = batches[batches.size() - 1];
FSTMutationBatch *notFound = self.mutationQueue->NextMutationBatchAfterBatchId(last.batchID);
2018-03-30 10:18:25 -07:00
XCTAssertNil(notFound);
});
2017-10-03 08:55:22 -07:00
}
- (void)testAllMutationBatchesAffectingDocumentKey {
if ([self isTestBaseClass]) return;
2018-03-30 10:18:25 -07:00
self.persistence.run("testAllMutationBatchesAffectingDocumentKey", [&]() {
NSArray<FSTMutation *> *mutations = @[
FSTTestSetMutation(@"foi/bar", @{@"a" : @1}), FSTTestSetMutation(@"foo/bar", @{@"a" : @1}),
FSTTestPatchMutation("foo/bar", @{@"b" : @1}, {}),
FSTTestSetMutation(@"foo/bar/suffix/key", @{@"a" : @1}),
FSTTestSetMutation(@"foo/baz", @{@"a" : @1}), FSTTestSetMutation(@"food/bar", @{@"a" : @1})
2018-03-30 10:18:25 -07:00
];
2017-10-03 08:55:22 -07:00
2018-03-30 10:18:25 -07:00
// Store all the mutations.
NSMutableArray<FSTMutationBatch *> *batches = [NSMutableArray array];
for (FSTMutation *mutation in mutations) {
FSTMutationBatch *batch =
2019-03-06 14:51:30 -08:00
self.mutationQueue->AddMutationBatch([FIRTimestamp timestamp], {}, {mutation});
2018-03-30 10:18:25 -07:00
[batches addObject:batch];
}
2017-10-03 08:55:22 -07:00
2019-01-28 10:21:20 -08:00
std::vector<FSTMutationBatch *> expected{batches[1], batches[2]};
std::vector<FSTMutationBatch *> matches =
self.mutationQueue->AllMutationBatchesAffectingDocumentKey(testutil::Key("foo/bar"));
2017-10-03 08:55:22 -07:00
2019-02-07 22:03:17 -05:00
FSTAssertEqualVectors(matches, expected);
2018-03-30 10:18:25 -07:00
});
2017-10-03 08:55:22 -07:00
}
- (void)testAllMutationBatchesAffectingDocumentKeys {
if ([self isTestBaseClass]) return;
self.persistence.run("testAllMutationBatchesAffectingDocumentKey", [&]() {
NSArray<FSTMutation *> *mutations = @[
FSTTestSetMutation(@"fob/bar", @{@"a" : @1}), FSTTestSetMutation(@"foo/bar", @{@"a" : @1}),
FSTTestPatchMutation("foo/bar", @{@"b" : @1}, {}),
FSTTestSetMutation(@"foo/bar/suffix/key", @{@"a" : @1}),
FSTTestSetMutation(@"foo/baz", @{@"a" : @1}), FSTTestSetMutation(@"food/bar", @{@"a" : @1})
];
// Store all the mutations.
NSMutableArray<FSTMutationBatch *> *batches = [NSMutableArray array];
for (FSTMutation *mutation in mutations) {
FSTMutationBatch *batch =
2019-03-06 14:51:30 -08:00
self.mutationQueue->AddMutationBatch([FIRTimestamp timestamp], {}, {mutation});
[batches addObject:batch];
}
DocumentKeySet keys{
Key("foo/bar"),
Key("foo/baz"),
};
2019-01-28 10:21:20 -08:00
std::vector<FSTMutationBatch *> expected{batches[1], batches[2], batches[4]};
std::vector<FSTMutationBatch *> matches =
self.mutationQueue->AllMutationBatchesAffectingDocumentKeys(keys);
2019-02-07 22:03:17 -05:00
FSTAssertEqualVectors(matches, expected);
});
}
- (void)testAllMutationBatchesAffectingDocumentKeys_handlesOverlap {
if ([self isTestBaseClass]) return;
self.persistence.run("testAllMutationBatchesAffectingDocumentKeys_handlesOverlap", [&]() {
2019-02-07 22:03:17 -05:00
std::vector<FSTMutation *> group1 = {
FSTTestSetMutation(@"foo/bar", @{@"a" : @1}),
FSTTestSetMutation(@"foo/baz", @{@"a" : @1}),
};
FSTMutationBatch *batch1 =
2019-03-06 14:51:30 -08:00
self.mutationQueue->AddMutationBatch([FIRTimestamp timestamp], {}, std::move(group1));
2019-02-07 22:03:17 -05:00
std::vector<FSTMutation *> group2 = {FSTTestSetMutation(@"food/bar", @{@"a" : @1})};
2019-03-06 14:51:30 -08:00
self.mutationQueue->AddMutationBatch([FIRTimestamp timestamp], {}, std::move(group2));
2019-02-07 22:03:17 -05:00
std::vector<FSTMutation *> group3 = {
FSTTestSetMutation(@"foo/bar", @{@"b" : @1}),
};
FSTMutationBatch *batch3 =
2019-03-06 14:51:30 -08:00
self.mutationQueue->AddMutationBatch([FIRTimestamp timestamp], {}, std::move(group3));
DocumentKeySet keys{
Key("foo/bar"),
Key("foo/baz"),
};
2019-01-28 10:21:20 -08:00
std::vector<FSTMutationBatch *> expected{batch1, batch3};
std::vector<FSTMutationBatch *> matches =
self.mutationQueue->AllMutationBatchesAffectingDocumentKeys(keys);
2019-02-07 22:03:17 -05:00
FSTAssertEqualVectors(matches, expected);
});
}
2017-10-03 08:55:22 -07:00
- (void)testAllMutationBatchesAffectingQuery {
if ([self isTestBaseClass]) return;
2018-03-30 10:18:25 -07:00
self.persistence.run("testAllMutationBatchesAffectingQuery", [&]() {
NSArray<FSTMutation *> *mutations = @[
FSTTestSetMutation(@"fob/bar", @{@"a" : @1}), FSTTestSetMutation(@"foo/bar", @{@"a" : @1}),
FSTTestPatchMutation("foo/bar", @{@"b" : @1}, {}),
FSTTestSetMutation(@"foo/bar/suffix/key", @{@"a" : @1}),
FSTTestSetMutation(@"foo/baz", @{@"a" : @1}), FSTTestSetMutation(@"food/bar", @{@"a" : @1})
2018-03-30 10:18:25 -07:00
];
2017-10-03 08:55:22 -07:00
2018-03-30 10:18:25 -07:00
// Store all the mutations.
NSMutableArray<FSTMutationBatch *> *batches = [NSMutableArray array];
for (FSTMutation *mutation in mutations) {
FSTMutationBatch *batch =
2019-03-06 14:51:30 -08:00
self.mutationQueue->AddMutationBatch([FIRTimestamp timestamp], {}, {mutation});
2018-03-30 10:18:25 -07:00
[batches addObject:batch];
}
2017-10-03 08:55:22 -07:00
2019-01-28 10:21:20 -08:00
std::vector<FSTMutationBatch *> expected = {batches[1], batches[2], batches[4]};
2018-03-30 10:18:25 -07:00
FSTQuery *query = FSTTestQuery("foo");
2019-01-28 10:21:20 -08:00
std::vector<FSTMutationBatch *> matches =
self.mutationQueue->AllMutationBatchesAffectingQuery(query);
2017-10-03 08:55:22 -07:00
2019-02-07 22:03:17 -05:00
FSTAssertEqualVectors(matches, expected);
2018-03-30 10:18:25 -07:00
});
2017-10-03 08:55:22 -07:00
}
- (void)testRemoveMutationBatches {
if ([self isTestBaseClass]) return;
2018-03-30 10:18:25 -07:00
self.persistence.run("testRemoveMutationBatches", [&]() {
2019-01-28 10:21:20 -08:00
std::vector<FSTMutationBatch *> batches = [self createBatches:10];
2017-10-03 08:55:22 -07:00
2019-01-28 10:21:20 -08:00
self.mutationQueue->RemoveMutationBatch(batches[0]);
batches.erase(batches.begin());
2017-10-03 08:55:22 -07:00
2018-03-30 10:18:25 -07:00
XCTAssertEqual([self batchCount], 9);
2017-10-03 08:55:22 -07:00
2019-01-28 10:21:20 -08:00
std::vector<FSTMutationBatch *> found;
2017-10-03 08:55:22 -07:00
2019-01-28 10:21:20 -08:00
found = self.mutationQueue->AllMutationBatches();
2019-02-07 22:03:17 -05:00
FSTAssertEqualVectors(found, batches);
2019-01-28 10:21:20 -08:00
XCTAssertEqual(found.size(), 9);
2017-10-03 08:55:22 -07:00
2019-01-28 10:21:20 -08:00
self.mutationQueue->RemoveMutationBatch(batches[0]);
self.mutationQueue->RemoveMutationBatch(batches[1]);
self.mutationQueue->RemoveMutationBatch(batches[2]);
batches.erase(batches.begin(), batches.begin() + 3);
2018-03-30 10:18:25 -07:00
XCTAssertEqual([self batchCount], 6);
2017-10-03 08:55:22 -07:00
2019-01-28 10:21:20 -08:00
found = self.mutationQueue->AllMutationBatches();
2019-02-07 22:03:17 -05:00
FSTAssertEqualVectors(found, batches);
2019-01-28 10:21:20 -08:00
XCTAssertEqual(found.size(), 6);
2017-10-03 08:55:22 -07:00
2019-01-28 10:21:20 -08:00
self.mutationQueue->RemoveMutationBatch(batches[0]);
batches.erase(batches.begin());
2018-03-30 10:18:25 -07:00
XCTAssertEqual([self batchCount], 5);
2017-10-03 08:55:22 -07:00
2019-01-28 10:21:20 -08:00
found = self.mutationQueue->AllMutationBatches();
2019-02-07 22:03:17 -05:00
FSTAssertEqualVectors(found, batches);
2019-01-28 10:21:20 -08:00
XCTAssertEqual(found.size(), 5);
2017-10-03 08:55:22 -07:00
2019-01-28 10:21:20 -08:00
self.mutationQueue->RemoveMutationBatch(batches[0]);
batches.erase(batches.begin());
2018-03-30 10:18:25 -07:00
XCTAssertEqual([self batchCount], 4);
2017-10-03 08:55:22 -07:00
2019-01-28 10:21:20 -08:00
self.mutationQueue->RemoveMutationBatch(batches[0]);
batches.erase(batches.begin());
2018-03-30 10:18:25 -07:00
XCTAssertEqual([self batchCount], 3);
2017-10-03 08:55:22 -07:00
2019-01-28 10:21:20 -08:00
found = self.mutationQueue->AllMutationBatches();
2019-02-07 22:03:17 -05:00
FSTAssertEqualVectors(found, batches);
2019-01-28 10:21:20 -08:00
XCTAssertEqual(found.size(), 3);
XCTAssertFalse(self.mutationQueue->IsEmpty());
2018-03-30 10:18:25 -07:00
2019-01-28 10:21:20 -08:00
for (FSTMutationBatch *batch : batches) {
self.mutationQueue->RemoveMutationBatch(batch);
2018-11-01 09:44:30 -07:00
}
2019-01-28 10:21:20 -08:00
found = self.mutationQueue->AllMutationBatches();
XCTAssertEqual(found.size(), 0);
XCTAssertTrue(self.mutationQueue->IsEmpty());
2018-03-30 10:18:25 -07:00
});
2017-10-03 08:55:22 -07:00
}
- (void)testStreamToken {
if ([self isTestBaseClass]) return;
NSData *streamToken1 = [@"token1" dataUsingEncoding:NSUTF8StringEncoding];
NSData *streamToken2 = [@"token2" dataUsingEncoding:NSUTF8StringEncoding];
2018-03-30 10:18:25 -07:00
self.persistence.run("testStreamToken", [&]() {
2019-01-28 10:21:20 -08:00
self.mutationQueue->SetLastStreamToken(streamToken1);
2017-10-03 08:55:22 -07:00
2018-03-30 10:18:25 -07:00
FSTMutationBatch *batch1 = [self addMutationBatch];
[self addMutationBatch];
2017-10-03 08:55:22 -07:00
2019-01-28 10:21:20 -08:00
XCTAssertEqualObjects(self.mutationQueue->GetLastStreamToken(), streamToken1);
2017-10-03 08:55:22 -07:00
2019-01-28 10:21:20 -08:00
self.mutationQueue->AcknowledgeBatch(batch1, streamToken2);
XCTAssertEqualObjects(self.mutationQueue->GetLastStreamToken(), streamToken2);
2018-03-30 10:18:25 -07:00
});
2017-10-03 08:55:22 -07:00
}
2018-03-30 10:18:25 -07:00
#pragma mark - Helpers
2017-10-03 08:55:22 -07:00
/** Creates a new FSTMutationBatch with the next batch ID and a set of dummy mutations. */
- (FSTMutationBatch *)addMutationBatch {
return [self addMutationBatchWithKey:@"foo/bar"];
}
/**
* Creates a new FSTMutationBatch with the given key, the next batch ID and a set of dummy
* mutations.
*/
- (FSTMutationBatch *)addMutationBatchWithKey:(NSString *)key {
FSTSetMutation *mutation = FSTTestSetMutation(key, @{@"a" : @1});
2017-10-03 08:55:22 -07:00
FSTMutationBatch *batch =
2019-03-06 14:51:30 -08:00
self.mutationQueue->AddMutationBatch([FIRTimestamp timestamp], {}, {mutation});
2017-10-03 08:55:22 -07:00
return batch;
}
/**
* Creates an array of batches containing @a number dummy FSTMutationBatches. Each has a different
* batchID.
*/
2019-01-28 10:21:20 -08:00
- (std::vector<FSTMutationBatch *>)createBatches:(int)number {
std::vector<FSTMutationBatch *> batches;
2017-10-03 08:55:22 -07:00
for (int i = 0; i < number; i++) {
FSTMutationBatch *batch = [self addMutationBatch];
2019-01-28 10:21:20 -08:00
batches.push_back(batch);
2017-10-03 08:55:22 -07:00
}
return batches;
}
/** Returns the number of mutation batches in the mutation queue. */
2019-01-28 10:21:20 -08:00
- (size_t)batchCount {
return self.mutationQueue->AllMutationBatches().size();
2017-10-03 08:55:22 -07:00
}
/**
2018-11-06 14:24:06 -08:00
* Removes the first n entries from the the given batches and returns them.
2017-10-03 08:55:22 -07:00
*
2018-11-06 14:24:06 -08:00
* @param n The number of batches to remove.
2017-10-03 08:55:22 -07:00
* @param batches The array to mutate, removing entries from it.
* @return A new array containing all the entries that were removed from @a batches.
*/
2019-01-28 10:21:20 -08:00
- (std::vector<FSTMutationBatch *>)removeFirstBatches:(size_t)n
inBatches:(std::vector<FSTMutationBatch *> *)batches {
std::vector<FSTMutationBatch *> removed(batches->begin(), batches->begin() + n);
batches->erase(batches->begin(), batches->begin() + n);
2017-10-03 08:55:22 -07:00
2019-01-28 10:21:20 -08:00
for (FSTMutationBatch *batch : removed) {
self.mutationQueue->RemoveMutationBatch(batch);
}
2017-10-03 08:55:22 -07:00
return removed;
}
@end
NS_ASSUME_NONNULL_END