<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[209977] trunk/Source/WebCore</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/209977">209977</a></dd>
<dt>Author</dt> <dd>beidson@apple.com</dd>
<dt>Date</dt> <dd>2016-12-18 17:40:37 -0800 (Sun, 18 Dec 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>IndexedDB 2.0: Prefetch cursor records in the server.
https://bugs.webkit.org/show_bug.cgi?id=166014

Reviewed by Andy Estes.

No new tests (Covered by existing LayoutTests and PerformanceTests).

This patch implements the followng:
1 - After a backing store cursor completes a fetch in the server, it will schedule the next fetch
    even before the client requests one. It will do this up to a limited number of prefetches.
2 - Once a client request to advance the cursor comes in, we'll work our way through prefetched
    records instead of reading anything from disk, which might then cause us to continue prefetch.
3 - If any changes to the object store occur, it will throw away all previously fetched records
    (There's room for future improvement here)

* Modules/indexeddb/server/IDBBackingStore.h:

* Modules/indexeddb/server/IDBServer.cpp:
(WebCore::IDBServer::IDBServer::postDatabaseTask):

* Modules/indexeddb/server/MemoryIDBBackingStore.h:

* Modules/indexeddb/server/SQLiteIDBBackingStore.cpp:
(WebCore::IDBServer::SQLiteIDBBackingStore::deleteRange):
(WebCore::IDBServer::SQLiteIDBBackingStore::prefetchCursor):
* Modules/indexeddb/server/SQLiteIDBBackingStore.h:

* Modules/indexeddb/server/SQLiteIDBCursor.cpp:
(WebCore::IDBServer::SQLiteIDBCursor::objectStoreRecordsChanged):
(WebCore::IDBServer::SQLiteIDBCursor::prefetch):
(WebCore::IDBServer::SQLiteIDBCursor::advance):
* Modules/indexeddb/server/SQLiteIDBCursor.h:

* Modules/indexeddb/server/UniqueIDBDatabase.cpp:
(WebCore::IDBServer::UniqueIDBDatabase::performIterateCursor):
(WebCore::IDBServer::UniqueIDBDatabase::performPrefetchCursor):
(WebCore::IDBServer::UniqueIDBDatabase::postDatabaseTask):
* Modules/indexeddb/server/UniqueIDBDatabase.h:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbserverIDBBackingStoreh">trunk/Source/WebCore/Modules/indexeddb/server/IDBBackingStore.h</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbserverIDBServercpp">trunk/Source/WebCore/Modules/indexeddb/server/IDBServer.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbserverMemoryIDBBackingStoreh">trunk/Source/WebCore/Modules/indexeddb/server/MemoryIDBBackingStore.h</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbserverSQLiteIDBBackingStorecpp">trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbserverSQLiteIDBBackingStoreh">trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.h</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbserverSQLiteIDBCursorcpp">trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBCursor.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbserverSQLiteIDBCursorh">trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBCursor.h</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbserverUniqueIDBDatabasecpp">trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbserverUniqueIDBDatabaseh">trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (209976 => 209977)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-12-19 01:14:10 UTC (rev 209976)
+++ trunk/Source/WebCore/ChangeLog        2016-12-19 01:40:37 UTC (rev 209977)
</span><span class="lines">@@ -1,3 +1,44 @@
</span><ins>+2016-12-18  Brady Eidson  &lt;beidson@apple.com&gt;
+
+        IndexedDB 2.0: Prefetch cursor records in the server.
+        https://bugs.webkit.org/show_bug.cgi?id=166014
+
+        Reviewed by Andy Estes.
+
+        No new tests (Covered by existing LayoutTests and PerformanceTests).
+
+        This patch implements the followng:
+        1 - After a backing store cursor completes a fetch in the server, it will schedule the next fetch 
+            even before the client requests one. It will do this up to a limited number of prefetches.
+        2 - Once a client request to advance the cursor comes in, we'll work our way through prefetched
+            records instead of reading anything from disk, which might then cause us to continue prefetch.
+        3 - If any changes to the object store occur, it will throw away all previously fetched records
+            (There's room for future improvement here)
+
+        * Modules/indexeddb/server/IDBBackingStore.h:
+        
+        * Modules/indexeddb/server/IDBServer.cpp:
+        (WebCore::IDBServer::IDBServer::postDatabaseTask):
+        
+        * Modules/indexeddb/server/MemoryIDBBackingStore.h:
+        
+        * Modules/indexeddb/server/SQLiteIDBBackingStore.cpp:
+        (WebCore::IDBServer::SQLiteIDBBackingStore::deleteRange):
+        (WebCore::IDBServer::SQLiteIDBBackingStore::prefetchCursor):
+        * Modules/indexeddb/server/SQLiteIDBBackingStore.h:
+        
+        * Modules/indexeddb/server/SQLiteIDBCursor.cpp:
+        (WebCore::IDBServer::SQLiteIDBCursor::objectStoreRecordsChanged):
+        (WebCore::IDBServer::SQLiteIDBCursor::prefetch):
+        (WebCore::IDBServer::SQLiteIDBCursor::advance):
+        * Modules/indexeddb/server/SQLiteIDBCursor.h:
+        
+        * Modules/indexeddb/server/UniqueIDBDatabase.cpp:
+        (WebCore::IDBServer::UniqueIDBDatabase::performIterateCursor):
+        (WebCore::IDBServer::UniqueIDBDatabase::performPrefetchCursor):
+        (WebCore::IDBServer::UniqueIDBDatabase::postDatabaseTask):
+        * Modules/indexeddb/server/UniqueIDBDatabase.h:
+
</ins><span class="cx"> 2016-12-18  Wenson Hsieh  &lt;wenson_hsieh@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Changing text direction fires input events with null inputTypes and no data
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverIDBBackingStoreh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/server/IDBBackingStore.h (209976 => 209977)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/IDBBackingStore.h        2016-12-19 01:14:10 UTC (rev 209976)
+++ trunk/Source/WebCore/Modules/indexeddb/server/IDBBackingStore.h        2016-12-19 01:40:37 UTC (rev 209977)
</span><span class="lines">@@ -91,6 +91,7 @@
</span><span class="cx">     virtual IDBError maybeUpdateKeyGeneratorNumber(const IDBResourceIdentifier&amp; transactionIdentifier, uint64_t objectStoreIdentifier, double newKeyNumber) = 0;
</span><span class="cx">     virtual IDBError openCursor(const IDBResourceIdentifier&amp; transactionIdentifier, const IDBCursorInfo&amp;, IDBGetResult&amp; outResult) = 0;
</span><span class="cx">     virtual IDBError iterateCursor(const IDBResourceIdentifier&amp; transactionIdentifier, const IDBResourceIdentifier&amp; cursorIdentifier, const IDBIterateCursorData&amp;, IDBGetResult&amp; outResult) = 0;
</span><ins>+    virtual bool prefetchCursor(const IDBResourceIdentifier&amp; transactionIdentifier, const IDBResourceIdentifier&amp; cursorIdentifier) = 0;
</ins><span class="cx"> 
</span><span class="cx">     virtual IDBObjectStoreInfo* infoForObjectStore(uint64_t objectStoreIdentifier) = 0;
</span><span class="cx">     virtual void deleteBackingStore() = 0;
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverIDBServercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/server/IDBServer.cpp (209976 => 209977)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/IDBServer.cpp        2016-12-19 01:14:10 UTC (rev 209976)
+++ trunk/Source/WebCore/Modules/indexeddb/server/IDBServer.cpp        2016-12-19 01:40:37 UTC (rev 209977)
</span><span class="lines">@@ -481,7 +481,6 @@
</span><span class="cx"> 
</span><span class="cx"> void IDBServer::postDatabaseTask(CrossThreadTask&amp;&amp; task)
</span><span class="cx"> {
</span><del>-    ASSERT(isMainThread());
</del><span class="cx">     m_databaseQueue.append(WTFMove(task));
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverMemoryIDBBackingStoreh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/server/MemoryIDBBackingStore.h (209976 => 209977)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/MemoryIDBBackingStore.h        2016-12-19 01:14:10 UTC (rev 209976)
+++ trunk/Source/WebCore/Modules/indexeddb/server/MemoryIDBBackingStore.h        2016-12-19 01:40:37 UTC (rev 209977)
</span><span class="lines">@@ -70,6 +70,7 @@
</span><span class="cx">     IDBError maybeUpdateKeyGeneratorNumber(const IDBResourceIdentifier&amp; transactionIdentifier, uint64_t objectStoreIdentifier, double newKeyNumber) final;
</span><span class="cx">     IDBError openCursor(const IDBResourceIdentifier&amp; transactionIdentifier, const IDBCursorInfo&amp;, IDBGetResult&amp; outResult) final;
</span><span class="cx">     IDBError iterateCursor(const IDBResourceIdentifier&amp; transactionIdentifier, const IDBResourceIdentifier&amp; cursorIdentifier, const IDBIterateCursorData&amp;, IDBGetResult&amp; outResult) final;
</span><ins>+    bool prefetchCursor(const IDBResourceIdentifier&amp;, const IDBResourceIdentifier&amp;) final { return false; }
</ins><span class="cx"> 
</span><span class="cx">     IDBObjectStoreInfo* infoForObjectStore(uint64_t objectStoreIdentifier) final;
</span><span class="cx">     void deleteBackingStore() final;
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverSQLiteIDBBackingStorecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.cpp (209976 => 209977)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.cpp        2016-12-19 01:14:10 UTC (rev 209976)
+++ trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.cpp        2016-12-19 01:40:37 UTC (rev 209977)
</span><span class="lines">@@ -1606,6 +1606,8 @@
</span><span class="cx">             return error;
</span><span class="cx">         }
</span><span class="cx"> 
</span><ins>+        transaction-&gt;notifyCursorsOfChanges(objectStoreID);
+
</ins><span class="cx">         return { };
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="lines">@@ -2489,6 +2491,22 @@
</span><span class="cx">     return { };
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+bool SQLiteIDBBackingStore::prefetchCursor(const IDBResourceIdentifier&amp; transactionIdentifier, const IDBResourceIdentifier&amp; cursorIdentifier)
+{
+    LOG(IndexedDB, &quot;SQLiteIDBBackingStore::prefetchCursor&quot;);
+
+    ASSERT(m_sqliteDB);
+    ASSERT(m_sqliteDB-&gt;isOpen());
+
+    auto* cursor = m_cursors.get(cursorIdentifier);
+    if (!cursor || !cursor-&gt;transaction() || !cursor-&gt;transaction()-&gt;inProgress())
+        return false;
+
+    ASSERT_UNUSED(transactionIdentifier, cursor-&gt;transaction()-&gt;transactionIdentifier() == transactionIdentifier);
+
+    return cursor-&gt;prefetch();
+}
+
</ins><span class="cx"> IDBObjectStoreInfo* SQLiteIDBBackingStore::infoForObjectStore(uint64_t objectStoreIdentifier)
</span><span class="cx"> {
</span><span class="cx">     ASSERT(m_databaseInfo);
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverSQLiteIDBBackingStoreh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.h (209976 => 209977)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.h        2016-12-19 01:14:10 UTC (rev 209976)
+++ trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.h        2016-12-19 01:40:37 UTC (rev 209977)
</span><span class="lines">@@ -75,6 +75,7 @@
</span><span class="cx">     IDBError maybeUpdateKeyGeneratorNumber(const IDBResourceIdentifier&amp; transactionIdentifier, uint64_t objectStoreIdentifier, double newKeyNumber) final;
</span><span class="cx">     IDBError openCursor(const IDBResourceIdentifier&amp; transactionIdentifier, const IDBCursorInfo&amp;, IDBGetResult&amp; outResult) final;
</span><span class="cx">     IDBError iterateCursor(const IDBResourceIdentifier&amp; transactionIdentifier, const IDBResourceIdentifier&amp; cursorIdentifier, const IDBIterateCursorData&amp;, IDBGetResult&amp; outResult) final;
</span><ins>+    bool prefetchCursor(const IDBResourceIdentifier&amp;, const IDBResourceIdentifier&amp;) final;
</ins><span class="cx"> 
</span><span class="cx">     IDBObjectStoreInfo* infoForObjectStore(uint64_t objectStoreIdentifier) final;
</span><span class="cx">     void deleteBackingStore() final;
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverSQLiteIDBCursorcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBCursor.cpp (209976 => 209977)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBCursor.cpp        2016-12-19 01:14:10 UTC (rev 209976)
+++ trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBCursor.cpp        2016-12-19 01:40:37 UTC (rev 209977)
</span><span class="lines">@@ -42,6 +42,8 @@
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> namespace IDBServer {
</span><span class="cx"> 
</span><ins>+static const size_t prefetchLimit = 8;
+
</ins><span class="cx"> std::unique_ptr&lt;SQLiteIDBCursor&gt; SQLiteIDBCursor::maybeCreate(SQLiteIDBTransaction&amp; transaction, const IDBCursorInfo&amp; info)
</span><span class="cx"> {
</span><span class="cx">     auto cursor = std::make_unique&lt;SQLiteIDBCursor&gt;(transaction, info);
</span><span class="lines">@@ -235,6 +237,8 @@
</span><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    m_currentKeyForUniqueness = m_fetchedRecords.first().record.key;
+
</ins><span class="cx">     m_fetchedRecords.clear();
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -291,18 +295,22 @@
</span><span class="cx">     return true;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void SQLiteIDBCursor::prefetch()
</del><ins>+bool SQLiteIDBCursor::prefetch()
</ins><span class="cx"> {
</span><del>-    ASSERT(!m_fetchedRecords.isEmpty());
-    if (m_fetchedRecords.last().errored || m_fetchedRecords.last().completed)
-        return;
</del><ins>+    LOG(IndexedDB, &quot;SQLiteIDBCursor::prefetch() - Cursor already has %zu fetched records&quot;, m_fetchedRecords.size());
</ins><span class="cx"> 
</span><ins>+    if (m_fetchedRecords.isEmpty() || m_fetchedRecords.size() &gt;= prefetchLimit || m_fetchedRecords.last().isTerminalRecord())
+        return false;
+
</ins><span class="cx">     m_currentKeyForUniqueness = m_fetchedRecords.last().record.key;
</span><span class="cx">     fetch();
</span><ins>+
+    return m_fetchedRecords.size() &lt; prefetchLimit;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool SQLiteIDBCursor::advance(uint64_t count)
</span><span class="cx"> {
</span><ins>+    LOG(IndexedDB, &quot;SQLiteIDBCursor::advance() - Count %&quot; PRIu64 &quot;, %zu fetched records&quot;, count, m_fetchedRecords.size());
</ins><span class="cx">     ASSERT(count);
</span><span class="cx"> 
</span><span class="cx">     if (!m_fetchedRecords.isEmpty() &amp;&amp; m_fetchedRecords.first().isTerminalRecord()) {
</span><span class="lines">@@ -314,7 +322,8 @@
</span><span class="cx">         m_currentKeyForUniqueness = m_fetchedRecords.last().record.key;
</span><span class="cx"> 
</span><span class="cx">     // Drop already-fetched records up to `count` to see if we've already fetched the record we're looking for.
</span><del>-    for (size_t i = 0; i &lt; count &amp;&amp; !m_fetchedRecords.isEmpty(); ++i) {
</del><ins>+    bool hadCurrentRecord = !m_fetchedRecords.isEmpty();
+    for (; count &amp;&amp; !m_fetchedRecords.isEmpty(); --count) {
</ins><span class="cx">         if (m_fetchedRecords.first().isTerminalRecord())
</span><span class="cx">             break;
</span><span class="cx"> 
</span><span class="lines">@@ -323,11 +332,16 @@
</span><span class="cx"> 
</span><span class="cx">     // If we still have any records left, the first record is our new current record.
</span><span class="cx">     if (!m_fetchedRecords.isEmpty())
</span><del>-        return !m_fetchedRecords.first().isTerminalRecord();
</del><ins>+        return true;
</ins><span class="cx"> 
</span><span class="cx">     ASSERT(m_fetchedRecords.isEmpty());
</span><span class="cx"> 
</span><del>-    for (uint64_t i = 0; i &lt; count; ++i) {
</del><ins>+    // If we started out with a current record, we burnt a count on removing it.
+    // Replace that count now.
+    if (hadCurrentRecord)
+        ++count;
+
+    for (; count; --count) {
</ins><span class="cx">         if (!m_fetchedRecords.isEmpty()) {
</span><span class="cx">             ASSERT(m_fetchedRecords.size() == 1);
</span><span class="cx">             m_currentKeyForUniqueness = m_fetchedRecords.first().record.key;
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverSQLiteIDBCursorh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBCursor.h (209976 => 209977)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBCursor.h        2016-12-19 01:14:10 UTC (rev 209976)
+++ trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBCursor.h        2016-12-19 01:40:37 UTC (rev 209977)
</span><span class="lines">@@ -69,7 +69,7 @@
</span><span class="cx"> 
</span><span class="cx">     bool advance(uint64_t count);
</span><span class="cx">     bool iterate(const IDBKeyData&amp; targetKey, const IDBKeyData&amp; targetPrimaryKey);
</span><del>-    void prefetch();
</del><ins>+    bool prefetch();
</ins><span class="cx"> 
</span><span class="cx">     bool didComplete() const;
</span><span class="cx">     bool didError() const;
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverUniqueIDBDatabasecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp (209976 => 209977)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp        2016-12-19 01:14:10 UTC (rev 209976)
+++ trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp        2016-12-19 01:40:37 UTC (rev 209977)
</span><span class="lines">@@ -1232,9 +1232,21 @@
</span><span class="cx">     IDBGetResult result;
</span><span class="cx">     IDBError error = m_backingStore-&gt;iterateCursor(transactionIdentifier, cursorIdentifier, data, result);
</span><span class="cx"> 
</span><ins>+    if (error.isNull())
+        postDatabaseTask(createCrossThreadTask(*this, &amp;UniqueIDBDatabase::performPrefetchCursor, transactionIdentifier, cursorIdentifier));
+
</ins><span class="cx">     postDatabaseTaskReply(createCrossThreadTask(*this, &amp;UniqueIDBDatabase::didPerformIterateCursor, callbackIdentifier, error, result));
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void UniqueIDBDatabase::performPrefetchCursor(const IDBResourceIdentifier&amp; transactionIdentifier, const IDBResourceIdentifier&amp; cursorIdentifier)
+{
+    ASSERT(!isMainThread());
+    LOG(IndexedDB, &quot;(db) UniqueIDBDatabase::performPrefetchCursor&quot;);
+
+    if (m_backingStore-&gt;prefetchCursor(transactionIdentifier, cursorIdentifier))
+        postDatabaseTask(createCrossThreadTask(*this, &amp;UniqueIDBDatabase::performPrefetchCursor, transactionIdentifier, cursorIdentifier));
+}
+
</ins><span class="cx"> void UniqueIDBDatabase::didPerformIterateCursor(uint64_t callbackIdentifier, const IDBError&amp; error, const IDBGetResult&amp; result)
</span><span class="cx"> {
</span><span class="cx">     ASSERT(isMainThread());
</span><span class="lines">@@ -1685,7 +1697,6 @@
</span><span class="cx"> 
</span><span class="cx"> void UniqueIDBDatabase::postDatabaseTask(CrossThreadTask&amp;&amp; task)
</span><span class="cx"> {
</span><del>-    ASSERT(isMainThread());
</del><span class="cx">     m_databaseQueue.append(WTFMove(task));
</span><span class="cx">     ++m_queuedTaskCount;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverUniqueIDBDatabaseh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.h (209976 => 209977)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.h        2016-12-19 01:14:10 UTC (rev 209976)
+++ trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.h        2016-12-19 01:40:37 UTC (rev 209977)
</span><span class="lines">@@ -165,6 +165,8 @@
</span><span class="cx">     void performDeleteRecord(uint64_t callbackIdentifier, const IDBResourceIdentifier&amp; transactionIdentifier, uint64_t objectStoreIdentifier, const IDBKeyRangeData&amp;);
</span><span class="cx">     void performOpenCursor(uint64_t callbackIdentifier, const IDBResourceIdentifier&amp; transactionIdentifier, const IDBCursorInfo&amp;);
</span><span class="cx">     void performIterateCursor(uint64_t callbackIdentifier, const IDBResourceIdentifier&amp; transactionIdentifier, const IDBResourceIdentifier&amp; cursorIdentifier, const IDBIterateCursorData&amp;);
</span><ins>+    void performPrefetchCursor(const IDBResourceIdentifier&amp; transactionIdentifier, const IDBResourceIdentifier&amp; cursorIdentifier);
+
</ins><span class="cx">     void performActivateTransactionInBackingStore(uint64_t callbackIdentifier, const IDBTransactionInfo&amp;);
</span><span class="cx">     void performUnconditionalDeleteBackingStore();
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>