зеркало из https://github.com/mozilla/gecko-dev.git
Bug 857283 - 'Smarter caching of index update queries'. r=khuey.
--HG-- extra : rebase_source : 489638cea833b32d05471188cf3a0b96947404cc
This commit is contained in:
Родитель
b6eb22dd27
Коммит
f5b0b9ceea
|
@ -979,7 +979,6 @@ IDBObjectStore::UpdateIndexes(IDBTransaction* aTransaction,
|
|||
int64_t aObjectDataId,
|
||||
const nsTArray<IndexUpdateInfo>& aUpdateInfoArray)
|
||||
{
|
||||
nsCOMPtr<mozIStorageStatement> stmt;
|
||||
nsresult rv;
|
||||
|
||||
NS_ASSERTION(aObjectDataId != INT64_MIN, "Bad objectData id!");
|
||||
|
@ -987,41 +986,49 @@ IDBObjectStore::UpdateIndexes(IDBTransaction* aTransaction,
|
|||
NS_NAMED_LITERAL_CSTRING(objectDataId, "object_data_id");
|
||||
|
||||
if (aOverwrite) {
|
||||
stmt = aTransaction->GetCachedStatement(
|
||||
"DELETE FROM unique_index_data "
|
||||
"WHERE object_data_id = :object_data_id; "
|
||||
"DELETE FROM index_data "
|
||||
"WHERE object_data_id = :object_data_id");
|
||||
NS_ENSURE_TRUE(stmt, NS_ERROR_FAILURE);
|
||||
nsCOMPtr<mozIStorageStatement> deleteStmt =
|
||||
aTransaction->GetCachedStatement(
|
||||
"DELETE FROM unique_index_data "
|
||||
"WHERE object_data_id = :object_data_id; "
|
||||
"DELETE FROM index_data "
|
||||
"WHERE object_data_id = :object_data_id");
|
||||
NS_ENSURE_TRUE(deleteStmt, NS_ERROR_FAILURE);
|
||||
|
||||
mozStorageStatementScoper scoper(stmt);
|
||||
mozStorageStatementScoper scoper(deleteStmt);
|
||||
|
||||
rv = stmt->BindInt64ByName(objectDataId, aObjectDataId);
|
||||
rv = deleteStmt->BindInt64ByName(objectDataId, aObjectDataId);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = stmt->Execute();
|
||||
rv = deleteStmt->Execute();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
// Avoid lots of hash lookups for objectStores with lots of indexes by lazily
|
||||
// holding the necessary statements on the stack outside the loop.
|
||||
nsCOMPtr<mozIStorageStatement> insertUniqueStmt;
|
||||
nsCOMPtr<mozIStorageStatement> insertStmt;
|
||||
|
||||
uint32_t infoCount = aUpdateInfoArray.Length();
|
||||
for (uint32_t i = 0; i < infoCount; i++) {
|
||||
const IndexUpdateInfo& updateInfo = aUpdateInfoArray[i];
|
||||
|
||||
// Insert new values.
|
||||
|
||||
stmt = updateInfo.indexUnique ?
|
||||
aTransaction->GetCachedStatement(
|
||||
"INSERT INTO unique_index_data "
|
||||
"(index_id, object_data_id, object_data_key, value) "
|
||||
"VALUES (:index_id, :object_data_id, :object_data_key, :value)") :
|
||||
aTransaction->GetCachedStatement(
|
||||
"INSERT OR IGNORE INTO index_data ("
|
||||
"index_id, object_data_id, object_data_key, value) "
|
||||
"VALUES (:index_id, :object_data_id, :object_data_key, :value)");
|
||||
nsCOMPtr<mozIStorageStatement>& stmt =
|
||||
updateInfo.indexUnique ? insertUniqueStmt : insertStmt;
|
||||
|
||||
if (!stmt) {
|
||||
stmt = updateInfo.indexUnique ?
|
||||
aTransaction->GetCachedStatement(
|
||||
"INSERT INTO unique_index_data "
|
||||
"(index_id, object_data_id, object_data_key, value) "
|
||||
"VALUES (:index_id, :object_data_id, :object_data_key, :value)") :
|
||||
aTransaction->GetCachedStatement(
|
||||
"INSERT OR IGNORE INTO index_data ("
|
||||
"index_id, object_data_id, object_data_key, value) "
|
||||
"VALUES (:index_id, :object_data_id, :object_data_key, :value)");
|
||||
}
|
||||
NS_ENSURE_TRUE(stmt, NS_ERROR_FAILURE);
|
||||
|
||||
mozStorageStatementScoper scoper4(stmt);
|
||||
mozStorageStatementScoper scoper(stmt);
|
||||
|
||||
rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("index_id"),
|
||||
updateInfo.indexId);
|
||||
|
|
Загрузка…
Ссылка в новой задаче