Skip to content

Commit 5a2a98f

Browse files
committed
fix union stage
1 parent 69e9255 commit 5a2a98f

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

Firestore/Source/API/FIRPipelineBridge.mm

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -961,35 +961,41 @@ - (nullable id)get:(id)field
961961
@implementation FIRPipelineBridge {
962962
NSArray<FIRStageBridge *> *_stages;
963963
FIRFirestore *firestore;
964+
Boolean isUserDataRead;
964965
std::shared_ptr<Pipeline> cpp_pipeline;
965966
}
966967

967968
- (id)initWithStages:(NSArray<FIRStageBridge *> *)stages db:(FIRFirestore *)db {
968969
_stages = stages;
969970
firestore = db;
971+
isUserDataRead = NO;
970972
return [super init];
971973
}
972974

973975
- (void)executeWithCompletion:(void (^)(__FIRPipelineSnapshotBridge *_Nullable result,
974976
NSError *_Nullable error))completion {
975-
std::vector<std::shared_ptr<firebase::firestore::api::Stage>> cpp_stages;
976-
for (FIRStageBridge *stage in _stages) {
977-
cpp_stages.push_back([stage cppStageWithReader:firestore.dataReader]);
978-
}
979-
cpp_pipeline = std::make_shared<Pipeline>(cpp_stages, firestore.wrapped);
980-
981-
cpp_pipeline->execute([completion](StatusOr<api::PipelineSnapshot> maybe_value) {
982-
if (maybe_value.ok()) {
983-
__FIRPipelineSnapshotBridge *bridge = [[__FIRPipelineSnapshotBridge alloc]
984-
initWithCppSnapshot:std::move(maybe_value).ValueOrDie()];
985-
completion(bridge, nil);
986-
} else {
987-
completion(nil, MakeNSError(std::move(maybe_value).status()));
988-
}
989-
});
977+
[self cppPipelineWithReader:firestore.dataReader]->execute(
978+
[completion](StatusOr<api::PipelineSnapshot> maybe_value) {
979+
if (maybe_value.ok()) {
980+
__FIRPipelineSnapshotBridge *bridge = [[__FIRPipelineSnapshotBridge alloc]
981+
initWithCppSnapshot:std::move(maybe_value).ValueOrDie()];
982+
completion(bridge, nil);
983+
} else {
984+
completion(nil, MakeNSError(std::move(maybe_value).status()));
985+
}
986+
});
990987
}
991988

992989
- (std::shared_ptr<api::Pipeline>)cppPipelineWithReader:(FSTUserDataReader *)reader {
990+
if (!isUserDataRead) {
991+
std::vector<std::shared_ptr<firebase::firestore::api::Stage>> cpp_stages;
992+
for (FIRStageBridge *stage in _stages) {
993+
cpp_stages.push_back([stage cppStageWithReader:firestore.dataReader]);
994+
}
995+
cpp_pipeline = std::make_shared<Pipeline>(cpp_stages, firestore.wrapped);
996+
}
997+
998+
isUserDataRead = YES;
993999
return cpp_pipeline;
9941000
}
9951001

0 commit comments

Comments
 (0)