Message from discussion
Most Efficient Way to Insert 5000+ Contacts
Received: by 10.224.186.20 with SMTP id cq20mr2261328qab.8.1353036870435;
Thu, 15 Nov 2012 19:34:30 -0800 (PST)
X-BeenThere: android-developers@googlegroups.com
Received: by 10.49.116.139 with SMTP id jw11ls695603qeb.37.gmail; Thu, 15 Nov
2012 19:30:47 -0800 (PST)
Received: by 10.49.24.13 with SMTP id q13mr697117qef.33.1353036647401;
Thu, 15 Nov 2012 19:30:47 -0800 (PST)
Date: Thu, 15 Nov 2012 19:30:46 -0800 (PST)
From: Spiral123 <cumis...@gmail.com>
To: android-developers@googlegroups.com
Message-Id: <23532594-d2ec-485c-bb81-563639dedda4@googlegroups.com>
In-Reply-To: <950f9d04-bdda-43a0-97a3-14d3f6cd4717@googlegroups.com>
References: <950f9d04-bdda-43a0-97a3-14d3f6cd4717@googlegroups.com>
Subject: Re: Most Efficient Way to Insert 5000+ Contacts
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_Part_673_10304330.1353036646872"
------=_Part_673_10304330.1353036646872
Content-Type: multipart/alternative;
boundary="----=_Part_674_10457929.1353036646872"
------=_Part_674_10457929.1353036646872
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Don't do it in Android. Use your WebService to sync the desktop
application contacts to a Google contact list using the Contacts API v3
(https://developers.google.com/google-apps/contacts/v3/). You can add a
specific label to tag them to your application and even extend the tables
if you wish.
Once the updates are done on the server side the stock Google
synchronization service works really well to sync them automatically down
to the phone/tablet - with the added advantage that they will be
automatically available and kept up to date on all devices when they
connect.
As far as I am aware there is no published volume or rate limit on this API
- but I would be surprised if it was less than the 10k per day allowed for
calendar and tasks.
Nick
On Tuesday, November 13, 2012 7:34:25 PM UTC-5, prestona wrote:
>
> 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.
>
> 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 -- The Google recommended way which gave me my
> baseline of 13.5 minutes for 5300 contacts.
>
> 2) Bulk Inserts -- I read that buildInsert 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 source code and I
> don't get the feeling that bulkInsert is terribly efficient.
>
> 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.
>
> Does anyone have any experience with inserting 5000+ contacts or any
> possible ideas I could look into to help reduce my time? Or should I
> consider the ContentProviderOperation to be as optimized as it's going to
> get?
>
> Thanks.
>
------=_Part_674_10457929.1353036646872
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
<div>Don't do it in Android. Use your WebService to sync the desktop =
application contacts to a Google contact list using the Contacts API v3 (ht=
tps://developers.google.com/google-apps/contacts/v3/). You can add a =
specific label to tag them to your application and even extend the tables i=
f you wish.</div><div><br></div><div>Once the updates are done on the serve=
r side the stock Google synchronization service works really well to sync t=
hem automatically down to the phone/tablet - with the added advantage that =
they will be automatically available and kept up to date on all devices whe=
n they connect.</div><div><br></div><div>As far as I am aware there is no p=
ublished volume or rate limit on this API - but I would be surprised if it =
was less than the 10k per day allowed for calendar and tasks.<br><br></div>=
<div>Nick</div><div><br><br>On Tuesday, November 13, 2012 7:34:25 PM UTC-5,=
prestona wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin=
-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">I'm developing=
an application where a user can initially sync all his contacts with a des=
ktop application OTA. This is done through a web service call that gr=
abs a set of 100 contacts from the server, downloads and parses the informa=
tion, inserts the contacts into the Android Contact DB, acknowledges receip=
t 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 w=
hen a user has contacts on the order or 1000-2000, but a typical user of th=
is 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. &nbs=
p;For example, a sample set of approximately 5300 contacts can take about 1=
3.5 minutes to complete. Not bad, but I'd like it to be at least as&n=
bsp;efficient as iOS which runs about 8 minutes for the same data set =
if possible.<div><br></div><div>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 littl=
e help with regards to inserting thousands of contacts, but what I have fou=
nd seems to fall into these three groups:</div><div><br></div><div>1) Conte=
ntProviderOperation -- The Google recommended way which gave me my baseline=
of 13.5 minutes for 5300 contacts.</div><div><br></div><div>2) Bulk Insert=
s -- I read that buildInsert tends to be more efficient than appl=
yBatch, but when I tried to implement this myself it actually took 25 minut=
es 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 bul=
kInsert which comes more naturally via the backValueReference in the Conten=
tProviderOperation. Additionally, I looked at the source code and I d=
on't get the feeling that bulkInsert is terribly efficient. </div=
><div><br></div><div>3) Creating an optimized bulk insert using the Databas=
eUtils.InsertHelper and transactions -- Unfortunately, this seems geared to=
wards 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.</div><div><br></div><div>D=
oes anyone have any experience with inserting 5000+ contacts or any possibl=
e ideas I could look into to help reduce my time? Or should I conside=
r the ContentProviderOperation to be as optimized as it's going to get?</di=
v><div><br></div><div>Thanks.</div></blockquote></div>
------=_Part_674_10457929.1353036646872--
------=_Part_673_10304330.1353036646872--