English 中文(简体)
核心数据排序连接表效率
原标题:Core Data Ordered Join Table Efficiencies

我在我的应用程序中有一个复杂的核心数据映射,简化为与这个问题相关的部分如下图所示:

将此翻译成中文:alt text http://grab.by/2aLT 备用文本 http://grab.by/2aLT

我的问题是如何高效地获取排序过的Foo。假设在我的一个视图中,我有一个带有每个Foo的分节表。这些部分是类别。每个Foo的部分(在一个类别中)都有一个排序方式。

现在,我正在使用这个算法来获取它们:

  1. Fetch a list of all categories, sorted by name
  2. For each category, fetch the Sorted Foos, sorted by index ascending
  3. For each SortedFoo, fetch the associated Foo, stick in an array
  4. Take the Foos, now sorted by index in an array, and add this array to a 2D array
  5. Return the 2D array as the ordered foo s in each alphabetized category.

对我来说,这似乎无效率。 当然,必须找到更好的办法,以完成这种共同的手法。 没有人能够提出这样做的新途径?

最佳回答

我将使foo的排序索引在所有类别中都是通用的。然后,按索引获取所有按排序的Foo对象。

如果您正在使用提取的结果控制器,则可以将类别名称用作节名称关键路径。如果没有,则可以手动按类别名称进行分区。

UPDATE
Actually, keeping index the way you have it, you could fetch all Foo objects and sort first by Category and then by SortFoos index. You would still need to partition them by the Category name manually.

UPDATE 2
For example:

NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"sorted_positions.category.name" ascending:YES];
NSSortDescriptor *sortDescriptor2 = [[NSSortDescriptor alloc] initWithKey:@"sorted_positions.index" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, sortDescriptor2, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
问题回答

暂无回答




相关问题
What to look for in performance analyzer in VS 2008

What to look for in performance analyzer in VS 2008 I am using VS Team system and got the performance wizard and reports going. What benchmarks/process do I use? There is a lot of stuff in the ...

SQL Table Size And Query Performance

We have a number of items coming in from a web service; each item containing an unknown number of properties. We are storing them in a database with the following Schema. Items - ItemID - ...

How to speed up Visual Studio 2008? Add more resources?

I m using Visual Studio 2008 (with the latest service pack) I also have ReSharper 4.5 installed. ReSharper Code analysis/ scan is turned off. OS: Windows 7 Enterprise Edition It takes me a long time ...

Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

热门标签