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

Re: [IndexDB] Proposal for async API changes

From: Jonas Sicking <jonas@sicking.cc>
Date: Wed, 9 Jun 2010 15:52:29 -0700
Message-ID: <AANLkTinFW0o-DG88SvxmGSgrZfDUQ47ZdhsNgMfxnafO@mail.gmail.com>
To: "Tab Atkins Jr." <jackalmage@gmail.com>
Cc: Laxmi Narsimha Rao Oruganti <Laxmi.Oruganti@microsoft.com>, Jeremy Orlow <jorlow@chromium.org>, Shawn Wilsher <sdwilsh@mozilla.com>, Webapps WG <public-webapps@w3.org>
On Wed, Jun 9, 2010 at 3:36 PM, Tab Atkins Jr. <jackalmage@gmail.com> wrote:
> On Wed, Jun 9, 2010 at 3:27 PM, Jonas Sicking <jonas@sicking.cc> wrote:
>> I'm well aware of this. My argument is that I think we'll see people
>> write code like this:
>> results = [];
>> db.objectStore("foo").openCursor(range).onsuccess = function(e) {
>>  var cursor = e.result;
>>  if (!cursor) {
>>    weAreDone(results);
>>  }
>>  results.push(cursor.value);
>>  cursor.continue();
>> }
>> While the indexedDB implementation doesn't hold much data in memory at
>> a time, the webpage will hold just as much as if we had had a getAll
>> function. Thus we havn't actually improved anything, only forced the
>> author to write more code.
>> Put it another way: The raised concern is that people won't think
>> about the fact that getAll can load a lot of data into memory. And the
>> proposed solution is to remove the getAll function and tell people to
>> use openCursor. However if they weren't thinking about that a lot of
>> data will be in memory at one time, then why wouldn't they write code
>> like the above? Which results as just as much data being in memory?
> At the very least, explicitly loading things into an honest-to-god
> array can make it more obvious that you're eating memory in the form
> of a big array, as opposed to just a "magically transform my blob of
> data into something more convenient".

I don't fully understand this. getAll also returns an honest-to-god array.

> (That said, I dislike cursors and explicitly avoid them in my own
> code.  In the PHP db abstraction layer I wrote for myself, every query
> slurps the results into an array and just returns that - I don't give
> myself any access to the cursor at all.  I probably like this better
> simply because I can easily foreach through an array, while I can't do
> the same with a cursor unless I write some moderately more complex
> code.  I hate using while loops when foreach is beckoning to me.)

This is what I'd expect many/most people to do.

/ Jonas
Received on Wednesday, 9 June 2010 22:53:22 UTC

This archive was generated by hypermail 2.3.1 : Friday, 27 October 2017 07:26:25 UTC