diff --git a/lib/persistence.js b/lib/persistence.js index e2e32b0..f6fd96f 100644 --- a/lib/persistence.js +++ b/lib/persistence.js @@ -102,6 +102,14 @@ Persistence.prototype.persistCachedDatabase = function (cb) { }; +/** + * Queue a rewrite of the datafile + */ +Persistence.prototype.compactDatafile = function () { + this.db.executor.push({ this: this, fn: this.persistCachedDatabase, arguments: [] }); +}; + + /** * Set automatic compaction every interval ms * @param {Number} interval in milliseconds, with an enforced minimum of 5 seconds @@ -113,7 +121,7 @@ Persistence.prototype.setAutocompactionInterval = function (interval) { this.stopAutocompaction(); this.autocompactionIntervalId = setInterval(function () { - self.db.executor.push({ this: self, fn: self.persistCachedDatabase, arguments: [] }); + self.compactDatafile(); }, interval); }; diff --git a/package.json b/package.json index 93edf4f..ebef603 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nedb", - "version": "0.8.2", + "version": "0.8.3", "author": { "name": "tldr.io", "email": "hello@tldr.io"