NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];NSEntityDescription *entity = [NSEntityDescription entityForname:@"MessageObject" inManagedobjectContext:appDelegate.managedobjectContext];[fetchRequest setEntity:entity];NSSortDescriptor *sort= [[NSSortDescriptor alloc] initWithKey:@"createDate" ascending:NO selector:@selector(compare:)];[fetchRequest setSortDescriptors:[NSArray arrayWithObject:sort]];[fetchRequest setFetchBatchSize:5];
就是这样,那是我的获取请求.我甚至没有使用谓词,它需要超过10秒.对于导致这种情况的原因,我完全不知道.如果有人有任何想法或起点,请分享.
我也尝试过启用sqlite调试日志记录(-com.apple.CoreData.sqlDeBUG 1),但我从这个简单的fetch中获得了数千行输出.这是正常的吗?
2012-06-22 19:39:59.171 myapp[81825:15e03] about to execute fetch 2012-06-22 19:39:59.172 myapp[81825:15e03] CoreData: sql: SELECT 0,t0.Z_PK FROM ZMBNOTEOBJECT t0 ORDER BY t0.ZCREATEDATE DESC 2012-06-22 19:39:59.178 myapp[81825:15e03] CoreData: annotation: sql connection fetch time: 0.0061s 2012-06-22 19:39:59.179 myapp[81825:15e03] CoreData: annotation: total fetch execution time: 0.0067s for 2052 rows. 2012-06-22 19:39:59.179 myapp[81825:15e03] 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.ZISPENDINGliKE,t0.ZISPENDINGREAD,t0.ZISPENDINGSYNC,t0.ZLASTUPDATED,t0.ZLOCALLYMODIFIEDDATE,t0.ZMAINIDEA,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 2012-06-22 19:39:59.180 myapp[81825:15e03] CoreData: annotation: sql connection fetch time: 0.0008s 2012-06-22 19:39:59.181 myapp[81825:15e03] CoreData: annotation: total fetch execution time: 0.0018s for 15 rows. 2012-06-22 19:39:59.182 myapp[81825:15e03] CoreData: sql: SELECT 0,?) ORDER BY t0.ZCREATEDATE DESC liMIT 15 2012-06-22 19:39:59.186 myapp[81825:15e03] CoreData: annotation: sql connection fetch time: 0.0042s 2012-06-22 19:39:59.187 myapp[81825:15e03] CoreData: annotation: total fetch execution time: 0.0049s for 15 rows. 2012-06-22 19:39:59.187 myapp[81825:15e03] CoreData: sql: SELECT 0,?) ORDER BY t0.ZCREATEDATE DESC liMIT 15 2012-06-22 19:39:59.188 myapp[81825:15e03] CoreData: annotation: sql connection fetch time: 0.0008s 2012-06-22 19:39:59.189 myapp[81825:15e03] CoreData: annotation: total fetch execution time: 0.0014s for 15 rows.... (thousands of more lines similar to above)
我不太熟悉这个,但看起来它在.0067秒内获取了2052行.那么为什么之后会继续做更多的事情呢?如果完成获取行,请求是否应该完成?它是错误的数据还是什么?
此外,我已经删除了setFetchBatchSize – 摆脱了数千行,但获取请求仍然需要很长时间.这是我得到的输出:
2012-06-22 20:07:25.316 myapp[8927:707] about to execute fetch 2012-06-22 20:07:25.322 myapp[8927:707] CoreData: sql: SELECT 0,t0.Z4PENDINGREMOVENOTES FROM ZMBNOTEOBJECT t0 ORDER BY t0.ZCREATEDATE DESC 2012-06-22 20:07:26.758 myapp[8927:707] CoreData: annotation: sql connection fetch time: 1.0891s 2012-06-22 20:07:26.763 myapp[8927:707] CoreData: annotation: total fetch execution time: 1.4407s for 4000 rows. 2012-06-22 20:07:35.967 myapp[8927:707] finished fetching
奇怪的是,在20:07:26.763它显然表示4000行需要1.4407秒,但是在另外9秒内我没有得到输出“完成提取”(这是在[[self fetchedResultsController]之后出现的NSLog语句) ] performFetch:& error])怎么了?
解决方法 删除setFetchBatchSize.如果您的意图是一次性加载所有内容,只需将其删除即可.
此外,如果您需要加载所有属性,请添加:
fetchRequest.returnsObjectsAsFaults = NO;
它将加载每个实体并填充属性.
您可能只想加载某些属性,因此使用它来选择您需要的属性:
fetchRequest.propertIEsToFetch = ...
而且你已经完成了.
总结以上是内存溢出为你收集整理的iphone – 核心数据获取速度非常慢全部内容,希望文章能够帮你解决iphone – 核心数据获取速度非常慢所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)