-
Notifications
You must be signed in to change notification settings - Fork 296
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
Too slow #77
Comments
I doubt that you really need to use Like for your example I imagine something akin the following: [[[self getSomeData] then:^id(NSDictionary *notifications) {
NSMutableArray<FBLPromise *> *modelPromises = [NSMutableArray new];
for(id key in notifications) {
NSDictionary *notification = notifications[key];
NSString *notificationType = notification[@"data"][@"type"];
if ([notificationType isEqualToString:@"SOMEREFERENCE"] ||
[notificationType isEqualToString:@"conversation/deleteByInitiatingUser"]) {
FBLPromise<NSDictionary *> *userDataPromise =
[[FBLPromise wrapObjectCompletion:^(FBLPromiseObjectCompletion handler) {
[[[[[[FIRDatabase database] reference] child:USERS_TABLE]
queryOrderedByChild:@"user_id"]
queryEqualToValue:[[obj objectForKey:@"data"] objectForKey:@"user_id"]]
observeSingleEventOfType:FIRDataEventTypeValue
withBlock:handler];
}] then:^id(FIRDataSnapshot *snapshot) {
return snapshot.value.allObjects.firstObject;
}];
FBLPromise<NSDictionary *> *skillFoundPromise =
[[FBLPromise wrapObjectCompletion:^(FBLPromiseObjectCompletion handler) {
[[[[[[FIRDatabase database] reference] child:SOME_TABLE]
queryOrderedByChild:@"id"]
queryEqualToValue:[[obj objectForKey:@"data"] objectForKey:@"skill_id"]]
observeSingleEventOfType:FIRDataEventTypeValue
withBlock:handler];
}] then:^id(FIRDataSnapshot *snapshot) {
return snapshot.value.allObjects.firstObject;
}];
FNLPromise *modelPromise =
[[FBLPromise all:@[userDataPromise, skillFoundPromise]] then:^id(NSArray *values) {
NSDictionary *userData = values.firstObject;
NSDictionary *skillFound = values.lastObject;
return [[Model alloc] initWithUserData:userData skillFound:skillFound];
}];
[modelPromises addObject:modelPromise];
}
}
return [FBLPromise all:modelPromises];
}] then:^id(NSArray<Model *> *models) {
[MBProgressHUD hideHUDForView:self.view animated:YES];
[self do_some_ui_stuff];
return nil;
}]; Which can be simplified and refactored further, if you move some of the patterns into separate methods, for example. |
Thanks. I"ll try this
…On Thu 25 Oct, 2018, 7:50 AM Anthony Shoumikhin, ***@***.***> wrote:
Hi @chiragpurohit71085 <https://github.com/chiragpurohit71085>,
I doubt that you really need to use FBLPromiseAwait at all. Normally, you
should be good by simply chaining promises into pipelines, possibly with
the help of misc extensions
<https://github.com/google/promises/blob/master/g3doc/index.md#extensions>
operators.
Like for your example I imagine something akin the following:
[[[self getSomeData] then:^id(NSDictionary *notifications) {
NSMutableArray<FBLPromise *> *modelPromises = [NSMutableArray new];
for(id key in notifications) {
NSDictionary *notification = notifications[key];
NSString *notificationType = notification[@"data"][@"type"];
if ([notificationType isEqualToString:@"SOMEREFERENCE"] ||
[notificationType isEqualToString:@"conversation/deleteByInitiatingUser"]) {
FBLPromise<NSDictionary *> *userDataPromise =
[[FBLPromise wrapObjectCompletion:^(FBLPromiseObjectCompletion handler) {
[[[[[[FIRDatabase database] reference] child:USERS_TABLE]
queryOrderedByChild:@"user_id"]
queryEqualToValue:[[obj objectForKey:@"data"] objectForKey:@"user_id"]]
observeSingleEventOfType:FIRDataEventTypeValue
withBlock:handler];
}] then:^id(FIRDataSnapshot *snapshot) {
return snapshot.value.allObjects.firstObject;
}];
FBLPromise<NSDictionary *> *skillFoundPromise =
[[FBLPromise wrapObjectCompletion:^(FBLPromiseObjectCompletion handler) {
[[[[[[FIRDatabase database] reference] child:SOME_TABLE]
queryOrderedByChild:@"id"]
queryEqualToValue:[[obj objectForKey:@"data"] objectForKey:@"skill_id"]]
observeSingleEventOfType:FIRDataEventTypeValue
withBlock:handler];
}] then:^id(FIRDataSnapshot *snapshot) {
return snapshot.value.allObjects.firstObject;
}];
FNLPromise *modelPromise =
[[FBLPromise ***@***.***, skillFoundPromise]] then:^id(NSArray *values) {
NSDictionary *userData = values.firstObject;
NSDictionary *skillFound = values.lastObject;
return [[Model alloc] initWithUserData:userData skillFound:skillFound];
}];
[modelPromises addObject:modelPromise];
}
}
return [FBLPromise all:modelPromises];
}] then:^id(NSArray<Model *> *models) {
[MBProgressHUD hideHUDForView:self.view animated:YES];
[self do_some_ui_stuff];
return nil;
}];
Which can be simplified and refactored further, if you move some of the
patterns into separate methods, for example.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#77 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/APH9ifpTZZ_hMrIpauWJJSRgW-79lP6Uks5uoSAIgaJpZM4X4aZV>
.
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I had implemented FBLPromiseAwait for firebase. It basically gets some data from firebase node and iterate for various condition. This takes around 15 seconds for 605 records, while iteration with normal firebase functions takes only 2 to 3 seconds i.e
[[[[[[FIRDatabase database] reference] child:USERS_TABLE] queryOrderedByChild:@"user_id"] queryEqualToValue:[[obj objectForKey:@"data"] objectForKey:@"user_id"]] observeSingleEventOfType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot * _Nonnull snapshot){ ..........
Please help me if I am implementing anything wrong
here is my sample code FBLPromiseAwait.
` FBLPromise<NSMutableArray *> *promise = [FBLPromise
onQueue:dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL)
do:^id {
NSError *error;
NSDictionary *notifications = FBLPromiseAwait([self getSomeData], &error);
The text was updated successfully, but these errors were encountered: