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; throw e;
} }
yield this.db.compactRange();
return true; return true;
}); });

View File

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