@@ -961,35 +961,41 @@ - (nullable id)get:(id)field
961
961
@implementation FIRPipelineBridge {
962
962
NSArray <FIRStageBridge *> *_stages;
963
963
FIRFirestore *firestore;
964
+ Boolean isUserDataRead;
964
965
std::shared_ptr<Pipeline> cpp_pipeline;
965
966
}
966
967
967
968
- (id )initWithStages : (NSArray <FIRStageBridge *> *)stages db : (FIRFirestore *)db {
968
969
_stages = stages;
969
970
firestore = db;
971
+ isUserDataRead = NO ;
970
972
return [super init ];
971
973
}
972
974
973
975
- (void )executeWithCompletion : (void (^)(__FIRPipelineSnapshotBridge *_Nullable result,
974
976
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
+ });
990
987
}
991
988
992
989
- (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 ;
993
999
return cpp_pipeline;
994
1000
}
995
1001
0 commit comments