核心数据推断的迁移 - 自动“轻量级” vs手动 [英] Core Data Inferred Migration – Automatic "lightweight" vs Manual

查看:176
本文介绍了核心数据推断的迁移 - 自动“轻量级” vs手动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以一些简单的方式(删除属性,添加属性,删除索引)更新了现有iPhone应用程序的模型,并且可以使用自动轻量级迁移来迁移持久存储。

I've updated the model of an existing iPhone app in some simple ways (remove attribute, add attribute, remove index), and can use automatic lightweight migration to migrate the persistent store.

由于数据集的典型大小,处理时间并不重要,因此需要为用户提供反馈。

Due to the typical size of the data set, the processing time is not insignificant, and warrants feedback for the user.

NSMigrationManager 提供了一个简单但有用的 migrationProgress 值,可在执行迁移时发送KVO通知。这形成了提供反馈的基础,但是试图使用推断模型( [NSMappingModel inferredMappingModelForSourceModel:destinationModel:error:] )导致完全相同的数据集的时间大大不同。

NSMigrationManager provides a simple but useful migrationProgress value that sends KVO notifications as the migration is performed. That forms the basis of providing feedback, however attempting to use an inferred model ([NSMappingModel inferredMappingModelForSourceModel:destinationModel:error:]) results in drastically different timing for the exact same dataset.

原始iPhone(2G)上的个人资料结果,缓存大小:磁盘上为1.785 MB。

Profile results on an original iPhone (2G), Cache size: 1.785 MB on disk.

自动推断轻量级迁移

Automatic inferred lightweight migration

PROFILE: CacheManager -migrateStore
PROFILE:   0.6130 (+0.6130) models loaded
PROFILE:   1.1759 (+0.5629) delegate -CacheManagerWillMigrate:
PROFILE:   1.2516 (+0.0757) persistent store coordinator loaded
PROFILE:   5.1436 (+3.8920) automatic lightweight migration completed
PROFILE:   5.5435 (+0.3999) delegate -CacheManagerDidFinishMigration:withError:

strong>

Manual inferred migration

PROFILE: CacheManager -migrateStore
PROFILE:   0.6660 (+0.6660) models loaded
PROFILE:   1.1471 (+0.4811) inferred mapping model generated
PROFILE:   1.4046 (+0.2574) delegate -CacheManagerWillMigrate:
PROFILE:   1.5058 (+0.1013) persistent store coordinator loaded
PROFILE:   22.6952 (+21.1894) manual migration completed
PROFILE:   23.1478 (+0.4525) delegate -CacheManagerDidFinishMigration:withError:

,使用推断的模型,手动迁移的时间比自动迁移的时间长5倍!

So, with an inferred model, the manual migration takes over 5 times longer than automatic!

更新:模型加载

UPDATE: Model loading

核心数据文档 NSPersistentStoreCoordinator 迁移选项说:


NSInferMappingModelAutomaticallyOption

...协调器将尝试
推断映射模型,如果没有可以找到

... the coordinator will attempt to infer a mapping model if none can be found.



<这就是为什么XCode构建,编译,绑定的映射模型必须删除(或只是取消定位),以允许推断的轻量级迁移发生。

这是一个很大的不一致, c> 选项 NSPersistentStoreCoordinator -addPersistentStoreWithType:configuration:URL:options:error:在处理过程中绝对没有任何进度。

It's a big inconsistency, and the lightweight option that NSPersistentStoreCoordinator -addPersistentStoreWithType:configuration:URL:options:error: provides absolutely no indication of progress while processing.

任何人都可以提供一种支持的方法,在自动迁移期间获得 migrationProgress 是否可以将推断的映射模型配置为在手动处理过程中自动执行?

Can anybody provide a supported way to get the migrationProgress values during automatic migration, OR a way to configure an inferred mapping model to be as fast during manual processing as automatic?

更新:错误报告

UPDATE: Bug Report

告诉WWDC工程师,

Spoke to the engineers at WWDC and they've asked for a bug report requesting the migrationProgress for the automatic lightweight migration processing.

如果API已更新为添加进度报告..

I'll update again if the API is updated to add progress reporting..

推荐答案

目前Core Data使用私有类 NSSQLiteInPlaceMigrationManager ,以执行轻量级迁移。这是 NSMigrationManager 的子类,但处理 migrateStoreFromURL中的所有内容:type:options:withMappingModel:toDestinationURL:destinationType:destinationOptions:error:。从外观上看,这个类实际上是直接在SQLite存储上执行修改,而不是根据手动迁移的需要将所有内容都拉到内存中。

Currently Core Data uses a private class, NSSQLiteInPlaceMigrationManager, to perform lightweight migration. This is a subclass of NSMigrationManager, but handles everything itself in migrateStoreFromURL:type:options:withMappingModel:toDestinationURL:destinationType:destinationOptions:error:. From the looks of it, this class is actually performing alterations directly on the SQLite store instead of pulling everything into memory as required by manual migration.

这解释了为什么你看到轻量级的迁移完成得更快。

This explains why you're seeing the lightweight migration complete much faster.

不幸的是,即使你使用这些知识的私人API在幕后使用,它不会获得你以获得进度指示。对于 NSSQLiteInPlaceMigrationManager ,进度的值当前不会更改,它始终为零。 currentEntityMapping 的值似乎仍为nil。

Unfortunately, even if you use this knowledge of the private APIs that are being used behind the scenes, it doesn't gain you much for getting a progress indication. The value of progress is currently never changed for NSSQLiteInPlaceMigrationManager, it's always zero. The value of currentEntityMapping also seems to remain nil.

直到Apple提供API,的运气。你有雷达号,所以我可以打开一个重复吗?

Until Apple provides an API, it seems we're out of luck. Do you have a radar number so I can open a duplicate?

这篇关于核心数据推断的迁移 - 自动“轻量级” vs手动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆