-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Implement RTDB Query get #7110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement RTDB Query get #7110
Changes from 4 commits
7459b68
b9b4866
db9d956
c04d225
f59c837
8b90241
d3548c4
76a544c
c33d2c2
05784bf
14ef2d7
f753ccd
253f14c
2546839
953112c
f7df365
ce0e21e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,6 +64,18 @@ @implementation FOutstandingPut | |
|
|
||
| @end | ||
|
|
||
| @interface FOutstandingGet : NSObject | ||
|
|
||
| @property(nonatomic, strong) NSDictionary *request; | ||
| @property(nonatomic, copy) fbt_void_nsstring_id_nsstring onCompleteBlock; | ||
| @property(nonatomic) BOOL sent; | ||
|
|
||
| @end | ||
|
|
||
| @implementation FOutstandingGet | ||
|
|
||
| @end | ||
|
|
||
| typedef enum { | ||
| ConnectionStateDisconnected, | ||
| ConnectionStateGettingToken, | ||
|
|
@@ -92,9 +104,11 @@ - (void)sendOnDisconnectAction:(NSString *)action | |
| @property(nonatomic, strong) FConnection *realtime; | ||
| @property(nonatomic, strong) NSMutableDictionary *listens; | ||
| @property(nonatomic, strong) NSMutableDictionary *outstandingPuts; | ||
| @property(nonatomic, strong) NSMutableDictionary *outstandingGets; | ||
| @property(nonatomic, strong) NSMutableArray *onDisconnectQueue; | ||
| @property(nonatomic, strong) FRepoInfo *repoInfo; | ||
| @property(nonatomic, strong) FAtomicNumber *putCounter; | ||
| @property(nonatomic, strong) FAtomicNumber *getCounter; | ||
| @property(nonatomic, strong) FAtomicNumber *requestNumber; | ||
| @property(nonatomic, strong) NSMutableDictionary *requestCBHash; | ||
| @property(nonatomic, strong) FIRDatabaseConfig *config; | ||
|
|
@@ -128,8 +142,10 @@ - (id)initWithRepoInfo:(FRepoInfo *)repoInfo | |
|
|
||
| self.listens = [[NSMutableDictionary alloc] init]; | ||
| self.outstandingPuts = [[NSMutableDictionary alloc] init]; | ||
| self.outstandingGets = [[NSMutableDictionary alloc] init]; | ||
| self.onDisconnectQueue = [[NSMutableArray alloc] init]; | ||
| self.putCounter = [[FAtomicNumber alloc] init]; | ||
| self.getCounter = [[FAtomicNumber alloc] init]; | ||
| self.requestNumber = [[FAtomicNumber alloc] init]; | ||
| self.requestCBHash = [[NSMutableDictionary alloc] init]; | ||
| self.unackedListensCount = 0; | ||
|
|
@@ -309,6 +325,9 @@ - (BOOL)canSendWrites { | |
| return self->connectionState == ConnectionStateConnected; | ||
| } | ||
|
|
||
| - (BOOL)canSendReads { | ||
| return self->connectionState == ConnectionStateConnected; | ||
| } | ||
jmwski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| #pragma mark - | ||
| #pragma mark FConnection delegate methods | ||
|
|
||
|
|
@@ -707,6 +726,39 @@ - (void)sendPut:(NSNumber *)index { | |
| }]; | ||
| } | ||
|
|
||
| - (void)sendGet:(NSNumber *)index { | ||
jmwski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| NSAssert([self canSendReads], | ||
| @"sendGet called when not able to send reads"); | ||
| FOutstandingGet *get = self.outstandingGets[index]; | ||
| assert(get != nil); | ||
|
||
| if ([get sent]) { | ||
| return; | ||
| } | ||
| get.sent = YES; | ||
| [self sendAction:kFWPRequestActionGet | ||
| body:get.request | ||
| sensitive:NO | ||
| callback:^(NSDictionary *data) { | ||
| FOutstandingGet *currentGet = self.outstandingGets[index]; | ||
| if (currentGet == get) { | ||
| [self.outstandingGets removeObjectForKey:index]; | ||
| NSString *status = | ||
| [data objectForKey:kFWPResponseForActionStatus]; | ||
| id resultData = [data objectForKey:kFWPResponseForActionData]; | ||
| if ([status isEqualToString:kFWPResponseForActionStatusOk]) { | ||
| get.onCompleteBlock(status, resultData, nil); | ||
| return; | ||
| } | ||
| get.onCompleteBlock(status, nil, resultData); | ||
| } else { | ||
| FFLog(@"I-RDB034045", | ||
| @"Ignoring on complete for get %@ because it was " | ||
| @"already removed", | ||
| index); | ||
| } | ||
| }]; | ||
| } | ||
|
|
||
| - (void)sendUnlisten:(FPath *)path | ||
| queryParams:(FQueryParams *)queryParams | ||
| tagId:(NSNumber *)tagId { | ||
|
|
@@ -759,6 +811,44 @@ - (void)putInternal:(id)data | |
| } | ||
| } | ||
|
|
||
| - (void)get:(NSString *)pathString | ||
| withParams:(NSDictionary *)queryWireProtocolParams | ||
| withCallback:(fbt_void_nsstring_id_nsstring)onComplete { | ||
| NSMutableDictionary *request = [NSMutableDictionary | ||
| dictionaryWithObjectsAndKeys:pathString, kFWPRequestPath, | ||
| queryWireProtocolParams, | ||
| kFWPRequestQueries, nil]; | ||
| FOutstandingGet *get = [[FOutstandingGet alloc] init]; | ||
| get.request = request; | ||
| get.onCompleteBlock = onComplete; | ||
| get.sent = NO; | ||
|
|
||
| NSNumber *index = [self.getCounter getAndIncrement]; | ||
| self.outstandingGets[index] = get; | ||
|
|
||
| if (![self connected]) { | ||
| dispatch_after( | ||
| dispatch_time(DISPATCH_TIME_NOW, kPersistentConnGetConnectTimeout), | ||
| self.dispatchQueue, ^{ | ||
| FOutstandingGet *get = self.outstandingGets[index]; | ||
|
||
| if ([get sent]) { | ||
| return; | ||
| } | ||
| get.sent = YES; | ||
| [self.outstandingGets removeObjectForKey:index]; | ||
| get.onCompleteBlock(@"failed", nil, kPersistentConnOffline); | ||
| }); | ||
| return; | ||
| } | ||
|
|
||
| if ([self canSendReads]) { | ||
| FFLog(@"I-RDB034024", @"Was connected, and added as index: %@", index); | ||
jmwski marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| [self sendGet:index]; | ||
| } else { | ||
| FFLog(@"I-RDB034025", @"Was connected, and added as index: %@", index); | ||
| } | ||
|
||
| } | ||
|
|
||
| - (void)sendListen:(FOutstandingQuery *)listenSpec { | ||
| FQuerySpec *query = listenSpec.query; | ||
| FFLog(@"I-RDB034026", @"Listen for %@", query); | ||
|
|
@@ -1009,6 +1099,17 @@ - (void)restoreState { | |
| } | ||
| } | ||
|
|
||
| NSArray *getKeys = [[self.outstandingGets allKeys] | ||
| sortedArrayUsingSelector:@selector(compare:)]; | ||
| for (int i = 0; i < [getKeys count]; i++) { | ||
| if ([self.outstandingGets objectForKey:[keys objectAtIndex:i]] != nil) { | ||
jmwski marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| FFLog(@"I-RDB034037", @"Restoring get: %d", i); | ||
| [self sendGet:[keys objectAtIndex:i]]; | ||
jmwski marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } else { | ||
| FFLog(@"I-RDB034038", @"Restoring get: skipped nil: %d", i); | ||
| } | ||
| } | ||
|
|
||
| for (FTupleOnDisconnect *tuple in self.onDisconnectQueue) { | ||
| [self sendOnDisconnectAction:tuple.action | ||
| forPath:tuple.pathString | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.