W3C home > Mailing lists > Public > public-webapps@w3.org > April to June 2011

Re: [indexeddb] Count property on IDBCursor

From: Jonas Sicking <jonas@sicking.cc>
Date: Tue, 28 Jun 2011 12:49:55 -0700
Message-ID: <BANLkTimw16H2v4L7vbR0_K_Oq7W=k+UrpA@mail.gmail.com>
To: Israel Hilerio <israelh@microsoft.com>
Cc: "public-webapps@w3.org" <public-webapps@w3.org>
On Mon, Jun 27, 2011 at 10:42 AM, Israel Hilerio <israelh@microsoft.com> wrote:
> On Thursday, June 23, 2011 7:42 PM, Jonas Sicking wrote:
>> On Thu, Jun 23, 2011 at 5:34 PM, Israel Hilerio <israelh@microsoft.com>
>> wrote:
>> > Is there a reason why we don't have a count or number of records
>> > property on IDBCursor?  Pablo told me that we used to have one.  What
>> happened to it?
>> > It will be great to bring it back.
>>
>> The problem is that counting the number of records in a given range can be a
>> very expensive operation. There are various database implementations out
>> there that lets you get an approximate count for a given key range, but that
>> isn't good enough if since we want interoperability across implementations.
>>
>> Since getting an exact count is a pretty expensive operation generally, we
>> don't want to force implementations to always calculate the count every time
>> a cursor is created. Hence getting the count would have to be an
>> asynchronous operation, which would look pretty awkward as an API on the
>> cursor object I think.
>>
>> What could possibly make more sense is to add
>>
>> IDBRequest count(in IDBKeyRange range)
>>
>> on IDBObjectStore and IDBIndex. My main concern with that is that while
>> that seems like a pretty cheap operation, in the order of get(), it might be as
>> slow as creating a cursor and iterating each entry while increasing a counter
>> (minus the overhead of crossing between C++ and JS for every callback). But
>> maybe that's ok.
>>
>> / Jonas
>
> I understand where you're coming from regarding performance.  I like your idea of adding a count method to the IDBObjectStore and IDBIndex.  This will deal with the scenarios we're thinking about.  Do you want to add this to the spec or want us to do that?

Would be great if you could add this. Please do make the function able
to take both a IDBKeyRange or a value, like .get() and .delete() does.

/ Jonas
Received on Tuesday, 28 June 2011 19:51:00 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 18:49:45 GMT