RestKit,核心数据,神奇记录,大量数据和滞后UI [英] RestKit, Core Data, Magical Record, Lots of data and Lagging UI

查看:274
本文介绍了RestKit,核心数据,神奇记录,大量数据和滞后UI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程式储存有关餐厅的资料。他们的菜单,日程安排等。
Theres〜200个餐馆在DB。该应用程序用于通过单次检索这些地方,但它花了太多的时间加载,所以我决定一个一个加载数据。在启动应用程序询问服务器的地方的ids数组,然后通过API获取数据。

I got an app which stores data about restaurants. Their menu, schedule and so on. Theres ~200 restaurants in the DB by now. The app used to retrieve those places by a single shot, but it was taking too much time to load, so i decided to load the data one by one. On the start app asks the server for an array of place's ids, then get the data via API.

我设置完成块RK的操作到背景队列,但它didn不帮助。滚动运行不够流畅,有时该应用程序甚至死锁(sic!)或崩溃,在控制台中没有错误输出。我已经尝试使用仪器找到什么使UI变得不稳定,但没有成功。我甚至关闭图像加载和排序功能。我曾经有RK的请求调用包裹在@synchronized,所以我删除它,但没有效果。

I set completion blocks for RK's operations to background queues, but it didn't help. Scrolls are running not smoothy enough and sometimes the app even deadlocks(sic!) or crashes with no error output in the console. I've tried using Instruments to locate what makes UI go jerky, but didn't succeed. I even turned off image loading and sorting functions. I used to have RK's requests calls wrapped in @synchronized, so i removed it, but no effect.

从来没有想过我会面临这种问题后几个星期的经验与目标c。我试过了每一种可能的方式来到我的脑海,所以现在我有点放弃。

Never thought i'd be facing this kind of issue after few weeks of experience with objective-c. I've tried every possible way that came to my mind, so now im kinda giving up.

请帮助我:)

应用程式启动后, p>

The code below gets called 200 times right after the app start.

NSURLRequest *request = [[DEAPIService sharedInstance].manager requestWithObject:nil
                                                                              method:RKRequestMethodGET
                                                                                path:path
                                                                          parameters:params];
    //DLog(request.URL.absoluteString);

    NSManagedObjectContext *context = [NSManagedObjectContext MR_contextWithParent:[NSManagedObjectContext MR_contextForCurrentThread]];

    RKManagedObjectRequestOperation *operation = [[DEAPIService sharedInstance].manager managedObjectRequestOperationWithRequest:request
                                                                                                        managedObjectContext:context
                                                                                                                         success:success
                                                                                                                         failure:failure];

    // dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0);
    dispatch_queue_t backgroundQueue = dispatch_queue_create("com.name.bgqueue", NULL);
    operation.successCallbackQueue = backgroundQueue;

    [[DEAPIService sharedInstance].manager enqueueObjectRequestOperation:operation];

在此之前设置响应描述符。在DB中也有很多关系。我查找了DB的文件大小 - 它〜1.5Mb。我不知道如果会有超过1k的餐馆会发生什么。它是一种很好的方式来加载这种数据?

Response descriptors are set before that. And also there's many relations in the DB. I've looked up the DB's file size - it's ~1.5Mb. I wonder what will happen if there would be over 1k restaurants. Is it a good way to load this kind of data? What are the best practises?

推荐答案

好的,从提供的信息,你应该能够简化很多。现在,你的代码下降到一个低水平,参与线程和上下文管理,你想让RestKit整理出来。

Ok, from the information provided you should be able to simplify a lot. At the moment your code is dropping down to a low level and getting involved in threading and context management that you want to leave for RestKit to sort out. You have a properly configured object manager and core data stack by the looks of things so you should let it do the work.

这意味着删除请求,上下文和请求操作代码并简单地调用`getObjectsAtPath:parameters:success:failure:'。然后RestKit会处理后台的所有下载和映射,并保存上下文。

This means removing the request, context and request operation code and simply calling `getObjectsAtPath:parameters:success:failure:'. RestKit will then deal with all of the download and mapping in the background and save the context.

你应该真正在你的应用程序中使用抓取结果控制器,如果你他们会自动检测RestKit保存的更改,并更新您的UI。

You should also really be using fetched results controllers throughout your app, and if you are they will automatically detect the changes that RestKit has saved and update your UI.

一旦你这样做,任何阻止UI与RestKit和你的下载要求无关,应与后续图片管理/下载相关。

Once you have that, any blocking of the UI is unrelated to RestKit and your download requirement and should be related to subsequent image management / downloads.

这篇关于RestKit,核心数据,神奇记录,大量数据和滞后UI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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