Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1702)

Unified Diff: content/browser/indexed_db/leveldb/leveldb_transaction.cc

Issue 2708223002: IndexedDB: Optimize range deletion operations (e.g. clearing a store) (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/indexed_db/leveldb/leveldb_transaction.cc
diff --git a/content/browser/indexed_db/leveldb/leveldb_transaction.cc b/content/browser/indexed_db/leveldb/leveldb_transaction.cc
index 016e7dea72b90ed23f1247f28813119d1f615f56..76a7403ba5b2e91928040a3c36c8157918bd60cc 100644
--- a/content/browser/indexed_db/leveldb/leveldb_transaction.cc
+++ b/content/browser/indexed_db/leveldb/leveldb_transaction.cc
@@ -25,7 +25,7 @@ LevelDBTransaction::LevelDBTransaction(LevelDBDatabase* db)
data_(data_comparator_),
finished_(false) {}
-LevelDBTransaction::Record::Record() : deleted(false) {}
+LevelDBTransaction::Record::Record() {}
LevelDBTransaction::Record::~Record() {}
LevelDBTransaction::~LevelDBTransaction() {}
@@ -60,6 +60,29 @@ bool LevelDBTransaction::Remove(const StringPiece& key) {
return !Set(key, &empty, true);
}
+leveldb::Status LevelDBTransaction::RemoveRange(const StringPiece& begin,
+ const StringPiece& end,
+ bool upper_open) {
+ IDB_TRACE("LevelDBTransaction::RemoveRange");
+ data_.erase(data_.lower_bound(begin), data_.lower_bound(end));
+ if (!upper_open)
+ data_.erase(end);
+ std::unique_ptr<LevelDBIterator> it = CreateIterator();
+ leveldb::Status s;
+ for (s = it->Seek(begin);
+ s.ok() && it->IsValid() &&
+ (upper_open ? comparator_->Compare(it->Key(), end) < 0
+ : comparator_->Compare(it->Key(), end) <= 0);
+ s = it->Next()) {
+ std::unique_ptr<Record> record = base::MakeUnique<Record>();
+ record->key = it->Key().as_string();
+ record->deleted = true;
+ data_[record->key] = std::move(record);
+ }
+ NotifyIterators();
+ return s;
+}
+
leveldb::Status LevelDBTransaction::Get(const StringPiece& key,
std::string* value,
bool* found) {

Powered by Google App Engine
This is Rietveld 408576698