chain: compact db after pruning.

This commit is contained in:
Christopher Jeffrey 2017-05-15 03:42:14 -07:00
parent d9c7d7e874
commit 028fee9eee
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 11 additions and 3 deletions

View File

@ -748,6 +748,8 @@ ChainDB.prototype.prune = co(function* prune(tip) {
throw e;
}
yield this.db.compactRange();
return true;
});

View File

@ -401,14 +401,20 @@ LowlevelUp.prototype.approximateSize = function approximateSize(start, end) {
/**
* Compact range of keys.
* @param {String|Buffer} start - Start key.
* @param {String|Buffer} end - End key.
* @param {String|Buffer|null} start - Start key.
* @param {String|Buffer|null} end - End key.
* @returns {Promise}
*/
LowlevelUp.prototype.compactRange = function compactRange(start, end) {
var self = this;
if (!start)
start = new Buffer([0x00]);
if (!end)
end = new Buffer([0xff]);
return new Promise(function(resolve, reject) {
if (!self.loaded) {
reject(new Error('Database is closed.'));
@ -416,7 +422,7 @@ LowlevelUp.prototype.compactRange = function compactRange(start, end) {
}
if (!self.binding.compactRange) {
reject(new Error('Cannot compact range.'));
resolve();
return;
}