Skip to content

read data slow for large database in firebase in ios #1614

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

Closed
vijay-kachhadiya opened this issue Aug 1, 2018 · 8 comments
Closed

read data slow for large database in firebase in ios #1614

vijay-kachhadiya opened this issue Aug 1, 2018 · 8 comments
Assignees

Comments

@vijay-kachhadiya
Copy link

I am using firebase for my Chating app. I store all information about the user from there. Normally if Firebase database does not have large data it gives a quick response. But once data is an increase in the database it becomes too slow. The same database is working perfectly on my android app. Please help me with solving this issue.

I am using the following method for fetching data from firebase.

 -(void) get_grouplist_refresh_single{

@try{
    appDel.totalUnreadMsg = 0;
    [[FIRDatabase database] goOnline];
    FIRDatabaseReference *rootRef= [[FIRDatabase database] referenceWithPath:[NSString stringWithFormat:@"/users/%@/activeGroups",appDel.UserId]];
    [rootRef  observeSingleEventOfType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot * _Nonnull snapshot) {
        //NSLog(@"group: %@", snapshot.value);
        if ([snapshot exists]) {

            NSDictionary *postDict = snapshot.value;
            NSArray *key_dictionary=[postDict allKeys];
            if (key_dictionary.count > 0) {
                for (int i=0; i < key_dictionary.count; i++) {
                    [self set_listner_group :[key_dictionary objectAtIndex:i]];
                    [self load_all_active_groupmsg :[key_dictionary objectAtIndex:i]];
                    if(key_dictionary.count - 1 == i){

                    }

                }
            }else{

            }
        }else{
            [[FIRDatabase database] goOnline];
        }

    }];
} @catch (NSException *exception) {
    NSLog(@"NSException %@",exception);
} @finally {

}
 }

-(void) set_listner_group :(NSString*) strGroupId{

@try{
    FIRDatabaseReference *rootRef= [[FIRDatabase database] referenceWithPath:[NSString stringWithFormat:@"/groups/%@",strGroupId]];
    [rootRef  observeSingleEventOfType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot * _Nonnull snapshot) {
        if ([snapshot exists]) {
            //Do somthing base on requirements
        }

    }];
} @catch (NSException *exception) {
    NSLog(@"NSException %@",exception);
} @finally {

}
   }

  -(void) load_all_active_groupmsg :(NSString*)strgroupID{

FIRDatabaseHandle handlerLoadAllMsg = 0;
FIRDatabaseReference *rootRef= [[FIRDatabase database] referenceWithPath:[NSString stringWithFormat:@"/group_msgs/%@",strgroupID]];
[rootRef keepSynced:YES];
handlerLoadAllMsg = [rootRef observeEventType:FIRDataEventTypeChildAdded withBlock:^(FIRDataSnapshot *snapshot)
                     {
                         if (snapshot.exists)
                         {
                             [rootRef removeObserverWithHandle:handlerLoadAllMsg];
                         }
                     }]; 
   }
@ryanwilson
Copy link
Member

Hi @vijay444,

Can you give some information about what Firebase version you are using, and what iOS version this is on?

Also, how big is the database being pulled in? Is it highly nested, or is it flat?

@vijay-kachhadiya
Copy link
Author

vijay-kachhadiya commented Aug 2, 2018

Thank you for giving me reply sir.
We are using Following Firebase version here

  • Using Firebase (4.13.0)
  • Using FirebaseAnalytics (4.2.0)
  • Using FirebaseAuth (4.6.1)
  • Using FirebaseCore (4.0.20)
  • Using FirebaseDatabase (4.1.5)
  • Using FirebaseInstanceID (2.0.10)
  • Using FirebaseMessaging (2.2.0)

We are using ios os version as follow

  • IOS 10.3.3
  • iOS 11.4.1

Our Firebase database is big. The database contains 500+ users, 3000+ Group of chats, and 10000+ messages in a chat group.

Yes it's a nested database structure
I hope you are getting all the information here. Please help me to solve this issue. I am trying a lot but didn't get a solution.

Thank you

@morganchen12
Copy link
Contributor

@vijay444 can you try updating to Firebase 5.0+ and seeing if the issue still persists?

@michael-mckenna
Copy link

You need to paginate your data. Rights now you are pulling in everything at once at that reference path. See https://firebase.google.com/docs/firestore/query-data/query-cursors

@vijay-kachhadiya
Copy link
Author

vijay-kachhadiya commented Aug 7, 2018 via email

@morganchen12
Copy link
Contributor

@vijay444 can you run Instruments' time profiler and post the trace here? A screenshot will do fine.

@morganchen12 morganchen12 self-assigned this Aug 7, 2018
@pschneider
Copy link

I'm not really into the issue right now but could it also be because of some problems mentioned in #1477 and related issues?

@morganchen12
Copy link
Contributor

Closing due to inactivity.

@firebase firebase locked and limited conversation to collaborators Oct 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants