RESOLVED FIXED 89607
IndexedDB: refactor index-writing to be more self-contained
https://bugs.webkit.org/show_bug.cgi?id=89607
Summary IndexedDB: refactor index-writing to be more self-contained
Alec Flett
Reported 2012-06-20 15:37:27 PDT
IndexedDB: refactor index-writing to be more self-contained
Attachments
Patch (12.82 KB, patch)
2012-06-20 15:40 PDT, Alec Flett
no flags
Patch (12.89 KB, patch)
2012-06-20 16:21 PDT, Alec Flett
no flags
Patch (11.65 KB, patch)
2012-06-20 16:24 PDT, Alec Flett
no flags
Patch (11.62 KB, patch)
2012-06-21 12:00 PDT, Alec Flett
no flags
Patch (11.59 KB, patch)
2012-06-22 10:51 PDT, Alec Flett
no flags
Patch (11.36 KB, patch)
2012-06-22 14:22 PDT, Alec Flett
no flags
Patch (11.65 KB, patch)
2012-06-22 15:27 PDT, Alec Flett
no flags
Patch for landing (11.66 KB, patch)
2012-06-22 15:35 PDT, Joshua Bell
no flags
Alec Flett
Comment 1 2012-06-20 15:40:48 PDT
Alec Flett
Comment 2 2012-06-20 15:46:36 PDT
jsbell@ / dgrogan@ - this is purely a refactor, no new changes are introduced. This is also stacked on top of bug 86123, so must wait until that lands. The gist of the refactor is: - Broaden the scope of the existing PopulateIndexCallback to be a more general purpose utility class, renaming it IndexWriter - split the gathering (loadIndexKeysForValue) of indexKeys and the writing of index keys (writeIndexKeys), so they can happen at different times. - in putInternal, Call loadIndexKeysForValue rather than the first loop which previously created a list of indexKeys, and call writeIndexKeys rather than the second loop, which previously duplicated the same logic in order to write them. Ultimately this consolidates 3 duplicate sections of code into a single one, and allows you to gather the index keys for a given value without mutating the database in any way. I think eventually (after further refactoring) loadIndexKeysForValue will be called on the frontend, and writeIndexKeys will be called from the backend, and we'll essentially be passing a whole structure of (primaryKey, (index -> indexKeys)) from the frontend to the backend.
Alec Flett
Comment 3 2012-06-20 15:54:52 PDT
actually you can hold off a bit looking at this - I just realized if I break out the 'callback' stuff, then I can implement IndexWriter without even relying on the backend interface instance until write-time.
Alec Flett
Comment 4 2012-06-20 16:21:04 PDT
Alec Flett
Comment 5 2012-06-20 16:24:12 PDT
Alec Flett
Comment 6 2012-06-21 12:00:38 PDT
Alec Flett
Comment 7 2012-06-21 12:01:29 PDT
this is ready for review - it's not going to pass the bots until the other bug lands, because it won't apply cleanly.
David Grogan
Comment 8 2012-06-21 14:53:54 PDT
Comment on attachment 148854 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=148854&action=review > Source/WebCore/Modules/indexeddb/IDBObjectStoreBackendImpl.cpp:237 > + *errorMessage = String::format("Unable to add key to index '%s': the key does not satisfy its uniqueness requirements.", Yay for better error messages! Maybe we can add an IDBKey.toString() method and even include the key.
Alec Flett
Comment 9 2012-06-22 10:51:35 PDT
Joshua Bell
Comment 10 2012-06-22 11:57:08 PDT
Comment on attachment 149060 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=149060&action=review > Source/WebCore/Modules/indexeddb/IDBObjectStoreBackendImpl.cpp:231 > + if (!indexKey->isValid()) Can the logic here be reordered to match the substeps in the spec (5.1 "Object Store Storage Operation", step 7), to make it easier to see that it conforms? > Source/WebCore/Modules/indexeddb/IDBObjectStoreBackendImpl.cpp:275 > + if (indexKey && m_index->multiEntry() && indexKey->type() == IDBKey::ArrayType) Recommend assigning indexKey to a real RefPtr<> before using, although as written this looks okay.
Alec Flett
Comment 11 2012-06-22 14:22:39 PDT
Alec Flett
Comment 12 2012-06-22 14:24:27 PDT
Comment on attachment 149100 [details] Patch tony@ - r? cq? no logic is changing here, this is a pure refactor
Tony Chang
Comment 13 2012-06-22 14:49:23 PDT
Comment on attachment 149100 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=149100&action=review > Source/WebCore/Modules/indexeddb/IDBObjectStoreBackendImpl.cpp:222 > + IndexWriter(PassRefPtr<IDBIndexBackendImpl> index) Nit: explicit > Source/WebCore/Modules/indexeddb/IDBObjectStoreBackendImpl.cpp:223 > + : m_index(index) Nit: Too much indent here (should be 8 spaces total). > Source/WebCore/Modules/indexeddb/IDBObjectStoreBackendImpl.cpp:229 > + bool loadIndexKeysForValue(SerializedScriptValue* objectValue, > + const IDBKey* primaryKey = 0, > + String* errorMessage = 0) Nit: I think it's rare in WebKit style to wrap function declarations. If you do want to wrap it, only indent one level (8 spaces total). > Source/WebCore/Modules/indexeddb/IDBObjectStoreBackendImpl.cpp:249 > + m_indexKeys.append(indexKey); > + } else { Nit: You could early return true here and remove the else block. > Source/WebCore/Modules/indexeddb/IDBObjectStoreBackendImpl.cpp:269 > + bool writeIndexKeys(const IDBBackingStore::ObjectStoreRecordIdentifier* recordIdentifier, > + IDBBackingStore& backingStore, int64_t databaseId, int64_t objectStoreId, > + String* errorMessage = 0) Nit: Weird indent like above. > Source/WebCore/Modules/indexeddb/IDBObjectStoreBackendImpl.cpp:271 > + for (size_t i = 0; i < m_indexKeys.size(); i++) { Nit: ++i
Alec Flett
Comment 14 2012-06-22 15:27:01 PDT
Joshua Bell
Comment 15 2012-06-22 15:35:20 PDT
Created attachment 149123 [details] Patch for landing
WebKit Review Bot
Comment 16 2012-06-22 16:06:37 PDT
Comment on attachment 149123 [details] Patch for landing Clearing flags on attachment: 149123 Committed r121066: <http://trac.webkit.org/changeset/121066>
WebKit Review Bot
Comment 17 2012-06-22 16:06:53 PDT
All reviewed patches have been landed. Closing bug.
Note You need to log in before you can comment on or make changes to this bug.