W3C home > Mailing lists > Public > public-webapps@w3.org > January to March 2013

Re: IndexedDB, what were the issues? How do we stop it from happening again?

From: Alec Flett <alecflett@google.com>
Date: Mon, 18 Mar 2013 17:42:34 -0700
Message-ID: <CAHWpXeYDrcGns+Rv0KVGCcHkYFea-Cs9dDy4awyLzqW3pz21SA@mail.gmail.com>
To: Jonas Sicking <jonas@sicking.cc>
Cc: Alex Russell <slightlyoff@google.com>, Miko Nieminen <miko.nieminen@iki.fi>, Marcos Caceres <marcosscaceres@gmail.com>, Jeni Tennison <jeni@jenitennison.com>, Shwetank Dixit <shwetankd@opera.com>, "www-tag@w3.org" <www-tag@w3.org>, Webapps WG <public-webapps@w3.org>, Joshua Bell <jsbell@google.com>, Jonas Sicking <sicking@mozilla.com>, mlamouri <mlamouri@mozilla.com>, Tab Atkins <tabatkins@google.com>, Yehuda Katz <wycats@gmail.com>, Andrei Popescu <andreip@google.com>
> transactions - Also should be optional. Vital to complex apps, but totally

>  > not necessary for many.. there should be a default transaction, like
> > db.objectStore("foo").get("bar")
>
> I disagree. This would have made it too trivial to create pages that
> have race conditions. I.e. people would write code like:
>
> db.objectStore("foo").get("bar").onsuccess = function(e) {
>   db.objectStore("foo").set("bar", e.target.result + 1)
> }
>
> without realizing that that contains a race condition.
>
> Its always possible for users to hang themselves - the web platform has
lots of rope. I could name a dozen gotchas like that in the JavaScript
language alone. The fact that we introduced shared workers introduces a
whole mess of issues like that. Not to criticize either - I think its just
something that happens as you introduce more flexible capabilities into the
platform.

In the above example, you could approach this with automatic transactions -
all operations that run in the callback of another IDB operation run in the
same transaction. So the set() and the get() are in the same transaction.
When you need explicit transactional control then you use the transaction()
API.


> > transaction scoping - even when you do want transactions, the api is just
> > too verbose and repetitive for "get one key from one object store" -
> > db.transaction("foo").objectStore("foo").get("bar") - there should be
> > implicit (lightweight) transactions like db.objectStore("foo").get("bar")
>
> We used to have this exact syntax, but it got everyone confused about
> what how the implicit transaction actually worked.
>
> This is surprising to me - *shrug* - I assume it was like the automatic
transactions I mentioned above.


>
> > named object stores - frankly, for many use cases, a single objectStore
> is
> > all you need. a simple db.get("foo") would be sufficient. Simply naming a
> > "default" isn't bad - whats bad is all the onupgradeneeded scaffolding
> > required to create the objectstore in the first place.
>
> I think we should do this as part of a simple API. Similar to something
> like
>
> https://github.com/slightlyoff/async-local-storage
>
>
Yes! I mean that's kind of where this conversation took off... I just don't
think there should be an obvious distinction between "the API with the
transactions and versions" and "the one without." - if anything presenting
them in a unified fashion allows for developers to migrate as they need
individual features (Transactions, versions, etc)

Alec
Received on Tuesday, 19 March 2013 00:43:22 GMT

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