From 9e71dbd9e563a2b48cb98e98c06c095d49bc4815 Mon Sep 17 00:00:00 2001 From: Louis Chatriot Date: Tue, 16 Jul 2013 17:38:55 +0200 Subject: [PATCH] Expose db.persistence.compactDatafile --- lib/persistence.js | 10 +++++++++- package.json | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) 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"