This commit is contained in:
Christopher Jeffrey 2016-03-13 04:23:04 -07:00
parent 68e40200e2
commit 39265bfb6b

View File

@ -223,7 +223,7 @@ DataStore.prototype.get = function get(key, callback) {
return this._db.get(key, function(err, offset) {
if (err)
return callback(err);
if (isDirect(key, offset))
if (isDirect(key))
return callback(null, offset);
return self.getData(offset, callback);
});
@ -281,7 +281,7 @@ Batch.prototype.write = function write(callback) {
utils.forEachSerial(this.ops, function(op, next) {
if (op.type === 'put') {
if (isDirect(op.key, op.value)) {
if (isDirect(op.key)) {
batch.put(op.key, op.value);
return next();
}
@ -294,14 +294,16 @@ Batch.prototype.write = function write(callback) {
}
if (op.type === 'del') {
if (isDirect(op.key)) {
batch.del(op.key);
return next();
}
return self._db.get(op.key, function(err, offset) {
if (err && err.type !== 'NotFoundError')
return callback(err);
if (!offset)
return next();
batch.del(op.key);
if (isDirect(op.key, offset))
return next();
self.store.delData(offset, next);
});
}
@ -328,6 +330,8 @@ DataStore.prototype.iterator = function iterator(options) {
function Iterator(store, options) {
this.store = store;
this._db = store._db;
if (options && options.keys === false)
options.keys = true;
this.iterator = this._db.db.iterator(options);
}
@ -338,9 +342,8 @@ Iterator.prototype.seek = function seek(key) {
// Store coins, chain entries, dummies, lookup
// hashes directly in the db (unless they're
// the same length as offset).
function isDirect(key, data) {
function isDirect(key) {
return !/^(b\/b\/|t\/t\/)/.test(key);
return data.length !== 12 && (data.length <= 87 || data.length === 116);
}
Iterator.prototype.next = function next(callback) {
@ -349,7 +352,7 @@ Iterator.prototype.next = function next(callback) {
return callback(err);
if (value) {
if (isDirect(key, value))
if (isDirect(key))
return callback(null, key, value);
return self.getData(value, function(err, data) {
if (err)
@ -433,8 +436,8 @@ DataStore.prototype.put = function put(key, value, callback) {
callback = utils.wrap(callback, unlock);
if (isDirect(key, value))
return self._db.put(key, value, callback);
if (isDirect(key))
return this._db.put(key, value, callback);
return this.putData(value, function(err, offset) {
if (err)
@ -527,13 +530,14 @@ DataStore.prototype.del = function del(key, callback, force) {
callback = utils.wrap(callback, unlock);
if (isDirect(key))
return this._db.del(key, callback);
this._db.get(key, function(err, off) {
if (err && err.type !== 'NotFoundError')
return callback(err);
if (!off)
return callback();
if (isDirect(key, off))
return self._db.del(key, callback);
self.delData(off, function(err) {
if (err)
return callback(err);