@@ -64,18 +64,6 @@ @implementation FOutstandingPut
6464
6565@end
6666
67- @interface FOutstandingGet : NSObject
68-
69- @property (nonatomic , strong ) NSDictionary *request;
70- @property (nonatomic , copy ) fbt_void_nsstring_id_nsstring onCompleteBlock;
71- @property (nonatomic ) BOOL sent;
72-
73- @end
74-
75- @implementation FOutstandingGet
76-
77- @end
78-
7967typedef enum {
8068 ConnectionStateDisconnected,
8169 ConnectionStateGettingToken,
@@ -104,11 +92,9 @@ - (void)sendOnDisconnectAction:(NSString *)action
10492@property (nonatomic , strong ) FConnection *realtime;
10593@property (nonatomic , strong ) NSMutableDictionary *listens;
10694@property (nonatomic , strong ) NSMutableDictionary *outstandingPuts;
107- @property (nonatomic , strong ) NSMutableDictionary *outstandingGets;
10895@property (nonatomic , strong ) NSMutableArray *onDisconnectQueue;
10996@property (nonatomic , strong ) FRepoInfo *repoInfo;
11097@property (nonatomic , strong ) FAtomicNumber *putCounter;
111- @property (nonatomic , strong ) FAtomicNumber *getCounter;
11298@property (nonatomic , strong ) FAtomicNumber *requestNumber;
11399@property (nonatomic , strong ) NSMutableDictionary *requestCBHash;
114100@property (nonatomic , strong ) FIRDatabaseConfig *config;
@@ -142,10 +128,8 @@ - (id)initWithRepoInfo:(FRepoInfo *)repoInfo
142128
143129 self.listens = [[NSMutableDictionary alloc ] init ];
144130 self.outstandingPuts = [[NSMutableDictionary alloc ] init ];
145- self.outstandingGets = [[NSMutableDictionary alloc ] init ];
146131 self.onDisconnectQueue = [[NSMutableArray alloc ] init ];
147132 self.putCounter = [[FAtomicNumber alloc ] init ];
148- self.getCounter = [[FAtomicNumber alloc ] init ];
149133 self.requestNumber = [[FAtomicNumber alloc ] init ];
150134 self.requestCBHash = [[NSMutableDictionary alloc ] init ];
151135 self.unackedListensCount = 0 ;
@@ -325,10 +309,6 @@ - (BOOL)canSendWrites {
325309 return self->connectionState == ConnectionStateConnected;
326310}
327311
328- - (BOOL )canSendReads {
329- return self->connectionState == ConnectionStateConnected;
330- }
331-
332312#pragma mark -
333313#pragma mark FConnection delegate methods
334314
@@ -727,43 +707,6 @@ - (void)sendPut:(NSNumber *)index {
727707 }];
728708}
729709
730- - (void )sendGet : (NSNumber *)index {
731- NSAssert ([self canSendReads ],
732- @" sendGet called when not able to send reads" );
733- FOutstandingGet *get = self.outstandingGets [index];
734- NSAssert (get != nil , @" sendGet found no outstanding get at index %@ " ,
735- index);
736- if ([get sent ]) {
737- return ;
738- }
739- get.sent = YES ;
740- [self sendAction: kFWPRequestActionGet
741- body: get.request
742- sensitive: NO
743- callback: ^(NSDictionary *data) {
744- FOutstandingGet *currentGet = self.outstandingGets [index];
745- if (currentGet == get) {
746- [self .outstandingGets removeObjectForKey: index];
747- NSString *status =
748- [data objectForKey: kFWPResponseForActionStatus ];
749- id resultData = [data objectForKey: kFWPResponseForActionData ];
750- if (resultData == (id )[NSNull null ]) {
751- resultData = nil ;
752- }
753- if ([status isEqualToString: kFWPResponseForActionStatusOk ]) {
754- get.onCompleteBlock (status, resultData, nil );
755- return ;
756- }
757- get.onCompleteBlock (status, nil , resultData);
758- } else {
759- FFLog (@" I-RDB034045" ,
760- @" Ignoring on complete for get %@ because it was "
761- @" already removed" ,
762- index);
763- }
764- }];
765- }
766-
767710- (void )sendUnlisten : (FPath *)path
768711 queryParams : (FQueryParams *)queryParams
769712 tagId : (NSNumber *)tagId {
@@ -816,46 +759,6 @@ - (void)putInternal:(id)data
816759 }
817760}
818761
819- - (void )getDataAtPath : (NSString *)pathString
820- withParams : (NSDictionary *)queryWireProtocolParams
821- withCallback : (fbt_void_nsstring_id_nsstring)onComplete {
822- NSMutableDictionary *request = [NSMutableDictionary
823- dictionaryWithObjectsAndKeys: pathString, kFWPRequestPath ,
824- queryWireProtocolParams,
825- kFWPRequestQueries , nil ];
826- FOutstandingGet *get = [[FOutstandingGet alloc ] init ];
827- get.request = request;
828- get.onCompleteBlock = onComplete;
829- get.sent = NO ;
830-
831- NSNumber *index = [self .getCounter getAndIncrement ];
832- self.outstandingGets [index] = get;
833-
834- if (![self connected ]) {
835- dispatch_after (dispatch_time (DISPATCH_TIME_NOW,
836- kPersistentConnectionGetConnectTimeout ),
837- self.dispatchQueue , ^{
838- FOutstandingGet *get = self.outstandingGets [index];
839- if ([get sent ]) {
840- return ;
841- }
842- FFLog (@" I-RDB034045" ,
843- @" get %@ timed out waiting for a connection" ,
844- index);
845- get.sent = YES ;
846- [self .outstandingGets removeObjectForKey: index];
847- get.onCompleteBlock (kFWPResponseForActionStatusFailed ,
848- nil , kPersistentConnectionOffline );
849- });
850- return ;
851- }
852-
853- if ([self canSendReads ]) {
854- FFLog (@" I-RDB034024" , @" Sending get: %@ " , index);
855- [self sendGet: index];
856- }
857- }
858-
859762- (void )sendListen : (FOutstandingQuery *)listenSpec {
860763 FQuerySpec *query = listenSpec.query ;
861764 FFLog (@" I-RDB034026" , @" Listen for %@ " , query);
@@ -1095,30 +998,17 @@ - (void)restoreState {
1095998 [self sendListen: outstandingListen];
1096999 }];
10971000
1098- NSArray *putKeys = [[self .outstandingPuts allKeys ]
1001+ NSArray *keys = [[self .outstandingPuts allKeys ]
10991002 sortedArrayUsingSelector: @selector (compare: )];
1100- for (int i = 0 ; i < [putKeys count ]; i++) {
1101- if ([self .outstandingPuts objectForKey: [putKeys objectAtIndex: i]] !=
1102- nil ) {
1003+ for (int i = 0 ; i < [keys count ]; i++) {
1004+ if ([self .outstandingPuts objectForKey: [keys objectAtIndex: i]] != nil ) {
11031005 FFLog (@" I-RDB034037" , @" Restoring put: %d " , i);
1104- [self sendPut: [putKeys objectAtIndex: i]];
1006+ [self sendPut: [keys objectAtIndex: i]];
11051007 } else {
11061008 FFLog (@" I-RDB034038" , @" Restoring put: skipped nil: %d " , i);
11071009 }
11081010 }
11091011
1110- NSArray *getKeys = [[self .outstandingGets allKeys ]
1111- sortedArrayUsingSelector: @selector (compare: )];
1112- for (int i = 0 ; i < [getKeys count ]; i++) {
1113- if ([self .outstandingGets objectForKey: [getKeys objectAtIndex: i]] !=
1114- nil ) {
1115- FFLog (@" I-RDB034037" , @" Restoring get: %d " , i);
1116- [self sendGet: [getKeys objectAtIndex: i]];
1117- } else {
1118- FFLog (@" I-RDB034038" , @" Restoring get: skipped nil: %d " , i);
1119- }
1120- }
1121-
11221012 for (FTupleOnDisconnect *tuple in self.onDisconnectQueue ) {
11231013 [self sendOnDisconnectAction: tuple.action
11241014 forPath: tuple.pathString
0 commit comments