Changeset 209942 in webkit
- Timestamp:
- Dec 16, 2016 3:03:26 PM (7 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r209940 r209942 1 2016-12-16 Brady Eidson <beidson@apple.com> 2 3 More SQLiteIDBCursor refactoring. 4 https://bugs.webkit.org/show_bug.cgi?id=165956 5 6 Reviewed by Tim Horton. 7 8 No new tests (No behavior change). 9 10 This is a simple patch that encapsulates the current state of the cursor in one structure 11 which will allow for storing multiple-such states in the future (to support prefetching). 12 13 * Modules/indexeddb/server/SQLiteIDBCursor.cpp: 14 (WebCore::IDBServer::SQLiteIDBCursor::currentData): 15 (WebCore::IDBServer::SQLiteIDBCursor::resetAndRebindStatement): 16 (WebCore::IDBServer::SQLiteIDBCursor::advance): 17 (WebCore::IDBServer::SQLiteIDBCursor::advanceUnique): 18 (WebCore::IDBServer::SQLiteIDBCursor::markAsErrored): 19 (WebCore::IDBServer::SQLiteIDBCursor::internalAdvanceOnce): 20 (WebCore::IDBServer::SQLiteIDBCursor::iterate): 21 22 * Modules/indexeddb/server/SQLiteIDBCursor.h: 23 (WebCore::IDBServer::SQLiteIDBCursor::currentRecordRowID): 24 (WebCore::IDBServer::SQLiteIDBCursor::currentKey): 25 (WebCore::IDBServer::SQLiteIDBCursor::currentPrimaryKey): 26 (WebCore::IDBServer::SQLiteIDBCursor::currentValue): 27 (WebCore::IDBServer::SQLiteIDBCursor::didComplete): 28 (WebCore::IDBServer::SQLiteIDBCursor::didError): 29 1 30 2016-12-16 Jer Noble <jer.noble@apple.com> 2 31 -
trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBCursor.cpp
r209893 r209942 102 102 void SQLiteIDBCursor::currentData(IDBGetResult& result) 103 103 { 104 if (m_c ompleted) {105 ASSERT(!m_ errored);104 if (m_currentRecord.completed) { 105 ASSERT(!m_currentRecord.errored); 106 106 result = { }; 107 107 return; 108 108 } 109 109 110 result = { m_currentRecord. key, m_currentRecord.primaryKey, m_currentRecord.value ? *m_currentRecord.value : IDBValue() };110 result = { m_currentRecord.record.key, m_currentRecord.record.primaryKey, m_currentRecord.record.value ? *m_currentRecord.record.value : IDBValue() }; 111 111 } 112 112 … … 224 224 225 225 // If this cursor never fetched any records, we don't need to reset the statement. 226 if (m_currentRecord. key.isNull())226 if (m_currentRecord.record.key.isNull()) 227 227 return; 228 228 … … 231 231 // We might also have to change the statement from closed to open so we don't refetch the current key a second time. 232 232 if (m_cursorDirection == IndexedDB::CursorDirection::Next || m_cursorDirection == IndexedDB::CursorDirection::NextNoDuplicate) { 233 m_currentLowerKey = m_currentRecord. key;233 m_currentLowerKey = m_currentRecord.record.key; 234 234 if (!m_keyRange.lowerOpen) { 235 235 m_keyRange.lowerOpen = true; … … 238 238 } 239 239 } else { 240 m_currentUpperKey = m_currentRecord. key;240 m_currentUpperKey = m_currentRecord.record.key; 241 241 if (!m_keyRange.upperOpen) { 242 242 m_keyRange.upperOpen = true; … … 294 294 bool isUnique = m_cursorDirection == IndexedDB::CursorDirection::NextNoDuplicate || m_cursorDirection == IndexedDB::CursorDirection::PrevNoDuplicate; 295 295 296 if (m_c ompleted) {296 if (m_currentRecord.completed) { 297 297 LOG_ERROR("Attempt to advance a completed cursor"); 298 298 return false; … … 308 308 } 309 309 310 if (m_c ompleted)310 if (m_currentRecord.completed) 311 311 break; 312 312 } … … 317 317 bool SQLiteIDBCursor::advanceUnique() 318 318 { 319 IDBKeyData currentKey = m_currentRecord. key;320 321 while (!m_c ompleted) {319 IDBKeyData currentKey = m_currentRecord.record.key; 320 321 while (!m_currentRecord.completed) { 322 322 if (!advanceOnce()) 323 323 return false; 324 324 325 325 // If the new current key is different from the old current key, we're done. 326 if (currentKey.compare(m_currentRecord. key))326 if (currentKey.compare(m_currentRecord.record.key)) 327 327 return true; 328 328 } … … 346 346 void SQLiteIDBCursor::markAsErrored() 347 347 { 348 m_c ompleted = true;349 m_ errored = true;350 m_currentRecord RowID = 0;348 m_currentRecord.completed = true; 349 m_currentRecord.errored = true; 350 m_currentRecord.rowID = 0; 351 351 } 352 352 … … 355 355 ASSERT(m_transaction->sqliteTransaction()); 356 356 ASSERT(m_statement); 357 ASSERT(!m_c ompleted);358 359 m_currentRecord. value = nullptr;357 ASSERT(!m_currentRecord.completed); 358 359 m_currentRecord.record.value = nullptr; 360 360 361 361 int result = m_statement->step(); 362 362 if (result == SQLITE_DONE) { 363 m_completed = true;364 365 363 // When a cursor reaches its end, that is indicated by having undefined keys/values 366 364 m_currentRecord = { }; 367 m_currentRecordRowID = 0; 365 m_currentRecord.completed = true; 366 m_currentRecord.rowID = 0; 368 367 369 368 return AdvanceResult::Success; … … 376 375 } 377 376 378 m_currentRecord RowID = m_statement->getColumnInt64(0);379 ASSERT(m_currentRecord RowID);377 m_currentRecord.rowID = m_statement->getColumnInt64(0); 378 ASSERT(m_currentRecord.rowID); 380 379 381 380 Vector<uint8_t> keyData; 382 381 m_statement->getColumnBlobAsVector(1, keyData); 383 382 384 if (!deserializeIDBKeyData(keyData.data(), keyData.size(), m_currentRecord. key)) {383 if (!deserializeIDBKeyData(keyData.data(), keyData.size(), m_currentRecord.record.key)) { 385 384 LOG_ERROR("Unable to deserialize key data from database while advancing cursor"); 386 385 markAsErrored(); … … 392 391 // The primaryKey of an ObjectStore cursor is the same as its key. 393 392 if (m_indexID == IDBIndexInfo::InvalidId) { 394 m_currentRecord. primaryKey = m_currentRecord.key;393 m_currentRecord.record.primaryKey = m_currentRecord.record.key; 395 394 396 395 Vector<String> blobURLs, blobFilePaths; 397 auto error = m_transaction->backingStore().getBlobRecordsForObjectStoreRecord(m_currentRecord RowID, blobURLs, blobFilePaths);396 auto error = m_transaction->backingStore().getBlobRecordsForObjectStoreRecord(m_currentRecord.rowID, blobURLs, blobFilePaths); 398 397 if (!error.isNull()) { 399 398 LOG_ERROR("Unable to fetch blob records from database while advancing cursor"); … … 403 402 404 403 if (m_cursorType == IndexedDB::CursorType::KeyAndValue) 405 m_currentRecord. value = std::make_unique<IDBValue>(ThreadSafeDataBuffer::adoptVector(keyData), blobURLs, blobFilePaths);404 m_currentRecord.record.value = std::make_unique<IDBValue>(ThreadSafeDataBuffer::adoptVector(keyData), blobURLs, blobFilePaths); 406 405 } else { 407 if (!deserializeIDBKeyData(keyData.data(), keyData.size(), m_currentRecord. primaryKey)) {406 if (!deserializeIDBKeyData(keyData.data(), keyData.size(), m_currentRecord.record.primaryKey)) { 408 407 LOG_ERROR("Unable to deserialize value data from database while advancing index cursor"); 409 408 markAsErrored(); … … 425 424 if (result == SQLITE_ROW) { 426 425 objectStoreStatement.getColumnBlobAsVector(0, keyData); 427 m_currentRecord. value = std::make_unique<IDBValue>(ThreadSafeDataBuffer::adoptVector(keyData));426 m_currentRecord.record.value = std::make_unique<IDBValue>(ThreadSafeDataBuffer::adoptVector(keyData)); 428 427 } else if (result == SQLITE_DONE) { 429 428 // This indicates that the record we're trying to retrieve has been removed from the object store. … … 452 451 return result; 453 452 454 while (!m_c ompleted) {453 while (!m_currentRecord.completed) { 455 454 if (!result) 456 455 return false; … … 458 457 // Search for the next key >= the target if the cursor is a Next cursor, or the next key <= if the cursor is a Previous cursor. 459 458 if (m_cursorDirection == IndexedDB::CursorDirection::Next || m_cursorDirection == IndexedDB::CursorDirection::NextNoDuplicate) { 460 if (m_currentRecord. key.compare(targetKey) >= 0)459 if (m_currentRecord.record.key.compare(targetKey) >= 0) 461 460 break; 462 } else if (m_currentRecord. key.compare(targetKey) <= 0)461 } else if (m_currentRecord.record.key.compare(targetKey) <= 0) 463 462 break; 464 463 … … 467 466 468 467 if (targetPrimaryKey.isValid()) { 469 while (!m_c ompleted && !m_currentRecord.key.compare(targetKey)) {468 while (!m_currentRecord.completed && !m_currentRecord.record.key.compare(targetKey)) { 470 469 if (!result) 471 470 return false; … … 473 472 // Search for the next primary key >= the primary target if the cursor is a Next cursor, or the next key <= if the cursor is a Previous cursor. 474 473 if (m_cursorDirection == IndexedDB::CursorDirection::Next || m_cursorDirection == IndexedDB::CursorDirection::NextNoDuplicate) { 475 if (m_currentRecord. primaryKey.compare(targetPrimaryKey) >= 0)474 if (m_currentRecord.record.primaryKey.compare(targetPrimaryKey) >= 0) 476 475 break; 477 } else if (m_currentRecord. primaryKey.compare(targetPrimaryKey) <= 0)476 } else if (m_currentRecord.record.primaryKey.compare(targetPrimaryKey) <= 0) 478 477 break; 479 478 -
trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBCursor.h
r209893 r209942 61 61 62 62 int64_t objectStoreID() const { return m_objectStoreID; } 63 int64_t currentRecordRowID() const { return m_currentRecord RowID; }63 int64_t currentRecordRowID() const { return m_currentRecord.rowID; } 64 64 65 const IDBKeyData& currentKey() const { return m_currentRecord. key; }66 const IDBKeyData& currentPrimaryKey() const { return m_currentRecord. primaryKey; }67 IDBValue* currentValue() const { return m_currentRecord. value.get(); }65 const IDBKeyData& currentKey() const { return m_currentRecord.record.key; } 66 const IDBKeyData& currentPrimaryKey() const { return m_currentRecord.record.primaryKey; } 67 IDBValue* currentValue() const { return m_currentRecord.record.value.get(); } 68 68 69 69 bool advance(uint64_t count); 70 70 bool iterate(const IDBKeyData& targetKey, const IDBKeyData& targetPrimaryKey); 71 71 72 bool didComplete() const { return m_c ompleted; }73 bool didError() const { return m_ errored; }72 bool didComplete() const { return m_currentRecord.completed; } 73 bool didError() const { return m_currentRecord.errored; } 74 74 75 75 void objectStoreRecordsChanged(); … … 107 107 IDBKeyData m_currentUpperKey; 108 108 109 IDBCursorRecord m_currentRecord; 109 struct SQLiteCursorRecord { 110 IDBCursorRecord record; 111 bool completed { false }; 112 bool errored { false }; 113 int64_t rowID { 0 }; 114 }; 115 116 SQLiteCursorRecord m_currentRecord; 110 117 111 118 std::unique_ptr<SQLiteStatement> m_statement; … … 113 120 int64_t m_boundID { 0 }; 114 121 115 bool m_completed { false };116 bool m_errored { false };117 118 122 bool m_backingStoreCursor { false }; 119 int64_t m_currentRecordRowID { 0 };120 123 }; 121 124
Note: See TracChangeset
for help on using the changeset viewer.