新的核心数据实体与现有的相同:单独的实体还是其他解决方案? [英] New Core Data entity identical to existing one: separate entity or other solution?

查看:114
本文介绍了新的核心数据实体与现有的相同:单独的实体还是其他解决方案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

概述:我正在设计一个餐厅管理应用程序,我有一个名为Order的实体,其中有Items。由于餐厅可以运行多年,有成千上万的完成的订单,为了使我的应用程序的网络端更容易和保持数据库快速,我想介绍一个ClosedOrder的概念,这是一个

Overview: I'm designing a restaurant management application, and I have an entity called Order which has Items. Since a restaurant can operate for many years, with many thousands of completed 'orders', and in the interest of making the networking side of my application easier and keeping the database fast, I want to introduce the concept of a ClosedOrder, which is an Order has been paid for, esentially.

我有几个选项可以这样做:我可以添加一个isClosed属性到我的订单实体,并执行所有的获取请求'打开命令,但是这保持了在每次需要提取时都有数据库的大量记录的问题,由于我的应用程序的工作流程,这通常与Order实体相关。如果我理解正确,创建一个ClosedOrder子实体也会有同样的问题,因为Core Data将所有子实体存储在数据库的同一个表中。

I have a few options for doing this: I could add an isClosed attribute to my Order entity, and perform all fetch requests for 'open' orders with a predicate, but that keeps the problem of there being lots of records for the DB to go through every time a fetch is needed, which is often with the Order entity because of the workflow of my app. If I understand correctly, creating a 'ClosedOrder' subentity would also have the same problem, as Core Data stores all subentities in the same table in the database.

完全分离的实体愚蠢在这种情况下?还是我需要做的?对于我对数据库性能的总体缺乏了解,我深表歉意,Core Data是美丽的,因为它抽象了需要了解这一点,但同时它不能真正使它不重要,特别是在这样的情况下,性能

Is creating a completely separate entity foolish in this case? Or is it exactly what I need to do? I apologize for my overall lack of knowledge about database performance, Core Data is beautiful in that it abstracts needing to learn about that away, but at the same time it can't actually make it not important, especially in a case like this where performance could severely degrade if it's pushed far by my users.

推荐答案

如果您使用的是SQLite存储类型和isClosed属性是索引(实体编辑器面板中的设置),您可能有成千上万的订单,并且只有在过滤isClosed == YES时,仍然有一个漂亮,快速的抓取时间。

If you're using SQLite store type and the "isClosed" attribute is "Indexed" (a setting in your entity editor panel), you could have hundreds of thousands of orders and still have a nice, quick fetch time when filtering only for "isClosed == YES".

创建一个单独的实体不会真正吸引你的性能,但它会使它更难以维护时,事情改变(两个迁移步骤的价格,例如)。你仍然存储所有这些项目,SQLite是一个有竞争力的DB库,当它正确设置。在这里使用索引属性,然后生成一些测试数据,然后测量性能。我相信你会很满意。

Creating a separate entity won't really buy you much performance but it will make it more of a pain to maintain when things change (two migration steps for the price of one, for example). You're still storing all those items and SQLite is a competent DB library when it's setup correctly. Use an indexed attribute here, then generate some test data, then measure the performance. I'm sure you'll be satisfied.

这篇关于新的核心数据实体与现有的相同:单独的实体还是其他解决方案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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