插入5000多个Android联系人的最有效方法 [英] Most Efficient Way to Insert 5000+ Android Contacts

查看:62
本文介绍了插入5000多个Android联系人的最有效方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我意识到在各个地方都有一些涉及,包括(此处关于堆栈溢出),但我正在寻找人们可能使用过的其他解决方案。因此,请牢记这一点...

I realize this has been somewhat touched upon in various places including here on Stack Overflow, but I'm looking for any other solutions that people might have used. So with that in mind...

我正在开发一个应用程序,用户可以首先将所有联系人与桌面应用程序OTA同步。这是通过网络服务调用完成的,该服务从服务器中获取一组100个联系人,下载并解析信息,将联系人插入Android Contact DB,确认收到这些联系人,然后对下一组重复先前的步骤100个联系人,直到同步完成。当用户有订单或1000-2000个联系人时,此过程效果很好,但是此应用程序的典型用户可以轻松拥有5000-6000个联系人(高级用户的10000+以上),在这种情况下,花费的时间比I想要。例如,大约5300个联系人的样本集可能需要大约13.5分钟才能完成。不错,但我希望它至少与iOS一样有效,如果可能的话,同一数据集大约要运行8分钟。

I'm developing an application where a user can initially sync all his contacts with a desktop application OTA. This is done through a web service call that grabs a set of 100 contacts from the server, downloads and parses the information, inserts the contacts into the Android Contact DB, acknowledges receipt of these contacts, and then repeats the previous steps with the next set of 100 contacts until the sync is complete. This process works well when a user has contacts on the order or 1000-2000, but a typical user of this application can easily have 5000-6000 contacts (with power users having upwards of 10000+) in which case things take far longer than I'd like. For example, a sample set of approximately 5300 contacts can take about 13.5 minutes to complete. Not bad, but I'd like it to be at least as efficient as iOS which runs about 8 minutes for the same data set if possible.

我已经记录了每个步骤所花费的时间,毫无疑问,瓶颈似乎在于将数据插入Android Contract DB中。在浏览网络后,我发现插入数千个联系人方面几乎没有帮助,但是我发现这似乎属于以下三类:

I've logged the time it takes for each step and, unsurprisingly, the bottleneck appears to be with inserting the data into the Android contract DB. After scouring the web I've found little help with regards to inserting thousands of contacts, but what I have found seems to fall into these three groups:

1)ContentProviderOperation- -Google推荐的方法给了我5300个联系人13.5分钟的基线。

1) ContentProviderOperation -- The Google recommended way which gave me my baseline of 13.5 minutes for 5300 contacts.

2)批量插入-我读到builkInsert往往比applyBatch效率更高,但是当我自己尝试实现此功能时,实际上5250个联系人就花了25分钟。我有很多这样的感觉,这是因为我需要插入RawContact信息,然后保存生成的URI以用于创建bulkInsert的ContactsContract.Data,这自然通过ContentProviderOperation中的backValueReference来实现。另外,我看了看android的源代码,并没有感到bulkInsert非常有效。

2) Bulk Inserts -- I read that builkInsert tends to be more efficient than applyBatch, but when I tried to implement this myself it actually took 25 minutes for the same 5300 contacts. I have a feeling a lot of this is due to the fact that I need to insert the RawContact information and then save the resulting URI for use in creating the ContactsContract.Data for the bulkInsert which comes more naturally via the backValueReference in the ContentProviderOperation. Additionally, I looked at the android source code and I don't get the feeling that bulkInsert is terribly efficient.

3)使用DatabaseUtils.InsertHelper和事务创建优化的批量插入-不幸的是,这似乎适合那些创建自己的内容提供者的人,因为您需要访问基础数据库作为实例变量,我还没有看到如何使用本机联系人数据库来完成。

3) Creating an optimized bulk insert using the DatabaseUtils.InsertHelper and transactions -- Unfortunately, this seems geared towards those people who created their own content provider because you need access to the underlying DB as an instance variable and I've yet to see how that could be done with the native contacts DB.

有人在插入5000+个联系人方面有任何经验吗?或其他可以帮助我减少时间的想法?还是应该将ContentProviderOperation视为已达到最佳状态?

Does anyone have any experience with inserting 5000+ contacts or any other possible ideas I could look into to help reduce my time? Or should the ContentProviderOperation be considered as optimized as it's going to get?

推荐答案

不幸的是,我相信1是最佳选择。我怀疑与iPhone相比,您的大部分开销是内容提供商设计所固有的跨进程IPC。

Unfortunately, I believe 1 is the best option. I suspect a majority of your overhead in comparison to iPhone is in the cross process IPC inherent to the content provider design.

您对3的分析是正确的。

Your analysis of 3 is correct.

有根设备上的选项可以绕过内容提供商,但我怀疑那是您要寻找的东西。

There are options on rooted devices to go around the content provider but I doubt that is what you are looking for.

这篇关于插入5000多个Android联系人的最有效方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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