【发布时间】:2014-06-10 12:42:56
【问题描述】:
块内的获取请求大约需要 9 分钟来处理仪器 customerArray 上的检查有大约 60K 对象,而 CusCustomerAddress 模型有大约 30k 对象,所以我必须优化这次。
NSArray *customerArray=[engine getItemsForEntity:@"CusCustomer" predicate:nil error:nil];
NSPredicate *predicate = [NSPredicate predicateWithFormat:[NSString stringWithFormat:@"id1 == $idVar"]];
NSPredicate *predicateCustomerAddress = [NSPredicate predicateWithFormat:[NSString stringWithFormat:@"customerId == $customerIdVar AND addressType == $addressTypeVar"]];
[customerArray enumerateObjectsUsingBlock:^(CusCustomer *customer, NSUInteger idx, BOOL *stop) {
NSString *customerId=customer.id1;
NSString *addressType = ShippingAddress;
NSDictionary *variablesAddress = @{ @"customerIdVar" : customerId , @"addressTypeVar" : addressType};
NSArray *resultAddress = [engine getItemsForEntity:@"CusCustomerAddress" predicate:[predicateCustomerAddress predicateWithSubstitutionVariables:variablesAddress] error:nil];
if (resultAddress.count == 1 ) {
[customer addCustomerAddressObject:(CusCustomerAddress *)[resultAddress lastObject]];
}
else
{
DLogHp(@"More than one tuple Exist For this'id1' =\"%@\" in \"CusCustomerGroup\"",objId);
}
addressType = BillingAddress;
NSDictionary *variablesAddress1 = @{ @"customerIdVar" : customerId , @"addressTypeVar" : addressType};
NSArray *resultaddress1 = [engine getItemsForEntity:@"CusCustomerAddress" predicate:[predicateCustomerAddress predicateWithSubstitutionVariables:variablesAddress1] error:nil];
if (resultaddress1.count == 1 ) {
[customer addCustomerAddressObject:(CusCustomerAddress *)[resultaddress1 lastObject]];
}
else
{
DLogHp(@"More than one tuple Exist For this'id1' =\"%@\" in \"CusCustomerGroup\"",objId);
}
}];
}
【问题讨论】:
-
哇,你想做什么?如果要显示此数据,请使用 NSFetchedResultsController。
-
NSFetchedResultsController用于查看,这是数据处理,NSFetchedResultsController不会解决任何问题。
标签: ios iphone xcode core-data