我正在运行一个非常基本的获取请求,它返回大约 2000 个对象。我正在使用批处理大小为 15 的 NSFetchedResultsController。
predicate= [NSPredicate predicateWithFormat:@"ANY tags.tagName==%@", currentTagObject.tagName];
[fetchRequest setPredicate:predicate];
NSSortDescriptor *sort= [[NSSortDescriptor alloc] initWithKey:@"createDate" ascending:NO selector:@selector(compare:)];
[fetchRequest setSortDescriptors:[NSArray arrayWithObject:sort]];
[fetchRequest setFetchBatchSize:15];
self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:appDelegate.managedObjectContext sectionNameKeyPath:@"createDay" cacheName:nil];
但是,获取请求需要超过 10 秒。我已经启用了 SQLite 调试,所以我可以看到发生了什么。我认为它正在获取所有 2000 个实体,其中只有 15 个具有实际值,然后出于某种原因遍历 2000 个对象中的每一个并将它们错误地放入其中。
在提取过程中,这些行出现了数千次:
2012-06-22 21:14:47.546 app[9227:707] CoreData: annotation: sql connection fetch time: 0.0107s
2012-06-22 21:14:47.551 app[9227:707] CoreData: annotation: total fetch execution time: 0.0171s for 15 rows.
2012-06-22 21:14:47.568 app[9227:707] CoreData: sql: SELECT 0, t0.Z_PK, t0.Z_OPT, t0.ZAUTHOREMAIL, t0.ZAUTHORNAME, t0.ZCREATEDATE, t0.ZISGLOBAL, t0.ZISLOCKED, t0.ZISNEW, t0.ZISPENDINGDELETE, t0.ZISPENDINGSYNC, t0.ZLASTUPDATED, t0.ZLOCALLYMODIFIEDDATE, t0.ZMETALASTUPDATED, t0.ZNOTEID, t0.ZNUMBEROFCHILDREN, t0.ZPARENTAUTHOREMAIL, t0.ZPARENTNOTEID, t0.ZROOTAUTHOREMAIL, t0.ZROOTNOTEID, t0.Z4PENDINGADDNOTES, t0.Z4PENDINGREMOVENOTES FROM ZMBNOTEOBJECT t0 WHERE t0.Z_PK IN (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) ORDER BY t0.ZCREATEDATE DESC LIMIT 15
...thousands more lines exactly similar to the three above
我的表一次只显示 5 个单元格,所以我不知道为什么所有对象都会立即出现故障。这可能是什么原因造成的?为什么我什至不滚动表格,所有对象都会立即出现故障?是否可以在某个地方访问它们,也许是迭代的?调用是否NSArray *fetchedObjects = fetchedResultsController.fetchedObjects
会导致所有对象发生故障?