Removed all references to the useless datafileSize

pull/2/head
Louis Chatriot 12 years ago
parent 6eef1ffdba
commit c552e37772
  1. 10
      lib/persistence.js
  2. 75
      test/db.test.js
  3. 29
      test/persistence.test.js

@ -28,11 +28,6 @@ function Persistence (options) {
if (this.filename && options.nodeWebkitAppName) {
this.filename = Persistence.getNWAppFilename(options.nodeWebkitAppName, this.filename);
}
// We keep internally the number of lines in the datafile
// This will be used when/if I implement autocompacting when the datafile grows too big
// For now it is not urgent as autocompaction happens upon every restart
this.datafileSize = 0;
};
@ -149,8 +144,6 @@ Persistence.prototype.persistNewState = function (newDocs, cb) {
// In-memory only datastore
if (self.inMemoryOnly) { return callback(null); }
self.datafileSize += newDocs.length;
newDocs.forEach(function (doc) {
toPersist += model.serialize(doc) + '\n';
});
@ -210,7 +203,6 @@ Persistence.prototype.loadDatabase = function (cb) {
;
self.db.resetIndexes();
self.datafileSize = 0;
// In-memory only datastore
if (self.inMemoryOnly) { return callback(null); }
@ -229,11 +221,9 @@ Persistence.prototype.loadDatabase = function (cb) {
self.db.resetIndexes(treatedData);
} catch (e) {
self.db.resetIndexes(); // Rollback any index which didn't fail
self.datafileSize = 0;
return cb(e);
}
self.datafileSize = treatedData.length;
self.db.persistence.persistCachedDatabase(cb);
});
});

@ -32,7 +32,6 @@ describe('Database', function () {
, function (cb) {
d.loadDatabase(function (err) {
assert.isNull(err);
d.persistence.datafileSize.should.equal(0);
d.getAllData().length.should.equal(0);
return cb();
});
@ -170,24 +169,6 @@ describe('Database', function () {
});
});
it('datafileSize is incremented by 1 upon every insert', function (done) {
d.persistence.datafileSize.should.equal(0);
d.getAllData().length.should.equal(0);
d.insert({ a: 3 }, function () {
d.persistence.datafileSize.should.equal(1);
d.getAllData().length.should.equal(1);
d.insert({ a: 3 }, function () {
d.persistence.datafileSize.should.equal(2);
d.getAllData().length.should.equal(2);
d.insert({ a: 3 }, function () {
d.persistence.datafileSize.should.equal(3);
d.getAllData().length.should.equal(3);
done();
});
});
});
});
it('Modifying the insertedDoc after an insert doesnt change the copy saved in the database', function (done) {
d.insert({ a: 2, hello: 'world' }, function (err, newDoc) {
newDoc.hello = 'changed';
@ -886,29 +867,6 @@ describe('Database', function () {
});
});
it('datafileSize stays correct upon updates', function (done) {
d.insert({ a: 2 }, function () {
d.insert({ a: 3 }, function () {
d.insert({ a: 5 }, function () {
d.persistence.datafileSize.should.equal(3);
d.getAllData().length.should.equal(3);
d.update({ a: 3 }, { $set: { a: 4 } }, {}, function () {
d.persistence.datafileSize.should.equal(4);
d.getAllData().length.should.equal(3);
d.update({ a: { $in: [2, 4] } }, { $set: { a: 5 } }, { multi: true }, function () {
d.persistence.datafileSize.should.equal(6);
d.getAllData().length.should.equal(3);
done();
});
});
});
});
});
});
}); // ==== End of 'Update' ==== //
@ -1058,29 +1016,6 @@ describe('Database', function () {
});
});
it('datafileSize stays correct upon removes', function (done) {
d.insert({ a: 2 }, function () {
d.insert({ a: 3 }, function () {
d.insert({ a: 5 }, function () {
d.persistence.datafileSize.should.equal(3);
d.getAllData().length.should.equal(3);
d.remove({ a: 3 }, {}, function () {
d.persistence.datafileSize.should.equal(4);
d.getAllData().length.should.equal(2);
d.remove({ a: { $in: [2, 5] } }, { multi: true }, function () {
d.persistence.datafileSize.should.equal(6);
d.getAllData().length.should.equal(0);
done();
});
});
});
});
});
});
}); // ==== End of 'Remove' ==== //
@ -1096,12 +1031,10 @@ describe('Database', function () {
;
d.getAllData().length.should.equal(0);
d.persistence.datafileSize.should.equal(0);
fs.writeFile(testDb, rawData, 'utf8', function () {
d.loadDatabase(function () {
d.getAllData().length.should.equal(3);
d.persistence.datafileSize.should.equal(3);
assert.deepEqual(Object.keys(d.indexes), ['_id']);
@ -1125,12 +1058,10 @@ describe('Database', function () {
;
d.getAllData().length.should.equal(0);
d.persistence.datafileSize.should.equal(0);
fs.writeFile(testDb, rawData, 'utf8', function () {
d.loadDatabase(function () {
d.getAllData().length.should.equal(2);
d.persistence.datafileSize.should.equal(2);
assert.deepEqual(Object.keys(d.indexes), ['_id']);
@ -1182,7 +1113,6 @@ describe('Database', function () {
;
d.getAllData().length.should.equal(0);
d.persistence.datafileSize.should.equal(0);
d.ensureIndex({ fieldName: 'z' });
d.indexes.z.fieldName.should.equal('z');
@ -1198,7 +1128,6 @@ describe('Database', function () {
;
d.getAllData().length.should.equal(3);
d.persistence.datafileSize.should.equal(3);
d.indexes.z.tree.getNumberOfKeys().should.equal(3);
d.indexes.z.tree.search('1')[0].should.equal(doc1);
@ -1218,7 +1147,6 @@ describe('Database', function () {
;
d.getAllData().length.should.equal(0);
d.persistence.datafileSize.should.equal(0);
d.ensureIndex({ fieldName: 'z' });
d.ensureIndex({ fieldName: 'a' });
@ -1233,7 +1161,6 @@ describe('Database', function () {
;
d.getAllData().length.should.equal(3);
d.persistence.datafileSize.should.equal(3);
d.indexes.z.tree.getNumberOfKeys().should.equal(3);
d.indexes.z.tree.search('1')[0].should.equal(doc1);
@ -1258,7 +1185,6 @@ describe('Database', function () {
;
d.getAllData().length.should.equal(0);
d.persistence.datafileSize.should.equal(0);
d.ensureIndex({ fieldName: 'z', unique: true });
d.indexes.z.tree.getNumberOfKeys().should.equal(0);
@ -1268,7 +1194,6 @@ describe('Database', function () {
err.errorType.should.equal('uniqueViolated');
err.key.should.equal("1");
d.getAllData().length.should.equal(0);
d.persistence.datafileSize.should.equal(0);
d.indexes.z.tree.getNumberOfKeys().should.equal(0);
done();

@ -32,7 +32,6 @@ describe('Persistence', function () {
, function (cb) {
d.loadDatabase(function (err) {
assert.isNull(err);
d.persistence.datafileSize.should.equal(0);
d.getAllData().length.should.equal(0);
return cb();
});
@ -154,34 +153,6 @@ describe('Persistence', function () {
});
});
it('datafileSize is the size of the dataset upon a databaseLoad', function (done) {
var now = new Date()
, rawData = model.serialize({ _id: "1", a: 2, ages: [1, 5, 12] }) + '\n' +
model.serialize({ _id: "2", hello: 'world' }) + '\n' +
model.serialize({ _id: "3", nested: { today: now } })
;
d.getAllData().length.should.equal(0);
d.persistence.datafileSize.should.equal(0);
fs.writeFile(testDb, rawData, 'utf8', function () {
d.loadDatabase(function () {
d.getAllData().length.should.equal(3);
d.persistence.datafileSize.should.equal(3);
d.find({}, function (err, docs) {
docs.sort(function (a, b) { return a._id - b._id; });
docs.length.should.equal(3);
_.isEqual(docs[0], { _id: "1", a: 2, ages: [1, 5, 12] }).should.equal(true);
_.isEqual(docs[1], { _id: "2", hello: 'world' }).should.equal(true);
_.isEqual(docs[2], { _id: "3", nested: { today: now } }).should.equal(true);
done();
});
});
});
});
it('Calling loadDatabase after the data was modified doesnt change its contents', function (done) {
d.loadDatabase(function () {
d.insert({ a: 1 }, function (err) {

Loading…
Cancel
Save