我正在将Firebase用于我的聊天应用程序。我从那里存储有关用户的所有信息。通常,如果Firebase数据库没有大数据,它将给出快速响应。但是一旦数据库中的数据增加,它就会变得太慢。同一数据库在我的android应用程序上运行正常。请帮助我解决这个问题。
我正在使用以下方法从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];
}
}];
}