领域写入事务需要1分20秒

时间:2017-09-11 07:58:38

标签: ios objective-c realm

我有四个对象,分别是User,Subsection,Section和Department。 请检查班级图。 here

目前数据结构是这样的。

Department.m

@implementation Department

- (id)initWithData:(NSDictionary*)data {

    if (self = [super init]) {

        self.name = data[@"name"];
        self.isCollapsed = 0;
        self.isSearchCollapsed = 1;

        for (NSDictionary *dict in data[@"sections"])
        {
            Section *section = [[Section alloc] initWithData:dict andDepartmentName:self.name];
            [self.sections addObject:section];

            for (SubSection *subSection in section.sections)
            {
                [self.subSections addObject:subSection];
            }
        }

        for (NSDictionary *dict in data[@"userlist"])
        {
            User *user = [[User alloc] initWithData:dict withLoggedIn:NO];
            [self.users addObject:user];
        }

    }
    return self;
}

+ (NSString *)primaryKey {
    return @"name";
}

@end

Department.h

@interface Department : RLMObject

@property NSString *name;

@property (nonatomic, strong) RLMArray<Section> *sections;
@property (nonatomic, strong) RLMArray<SubSection> *subSections;
@property (nonatomic, strong) RLMArray<User> *users;

@property (nonatomic, strong) RLMArray<Section> *searchSections;
@property (nonatomic, strong) RLMArray<User> *searchUsers;
@end

栏目

@interface Section : RLMObject

@property NSString *name;
@property NSString *departmentName;
@property RLMArray<SubSection> *sections;
@property RLMArray<User> *users;
@property (nonatomic, strong) RLMArray<SubSection> *searchSections;
@property (nonatomic, strong) RLMArray<User> *searchUsers;

@end

@interface SubSection : RLMObject

@property NSString *name;
@property NSString *sectionName;
@property NSString *departmentName;
@property RLMArray<User> *users;
@property RLMArray<User> *searchUsers;

@end

用户

@interface User : RLMObject
@property NSString *department;
@property NSString *email;
@property NSString *firstname;
@property NSString *lastname;
@property NSString *fullname;
@property NSString *section;
@property NSString *subSection;
@end

这是写事务。请检查。

RLMRealm *realm = [RLMRealm defaultRealm];
    @try
    {
        for (NSDictionary *dict in result)
        {
            Department *department = [[Department alloc] initWithData:dict];
            [realm beginWriteTransaction];
            [realm addOrUpdateObject:department];
            [realm commitWriteTransaction];
        }

        successBlock();
    }
    @catch (NSException * e)
    {
        DLog(@"Exception: %@", e.reason);
        failBlock(e);
    }

当我写作 用户 - 10660 部分 - 62 第156分节 部门 - 19 到这个领域,它需要1分20秒,即使android只需要40秒。有什么我必须解决的吗?数据结构与android和iOS相同。在用android检查后,用户正在抱怨这一点。

0 个答案:

没有答案