Remove lazy collections, remove unused caching stuff, unsupport node 0.4 (travis)

This commit is contained in:
Anatoliy Chakkaev 2012-10-16 02:22:40 +04:00
parent dbb39bf43e
commit 96e9079977
3 changed files with 10 additions and 93 deletions

View File

@ -1,8 +1,7 @@
language: node_js
node_js:
- 0.4.12
- 0.6
- 0.8.11
- 0.8.12
services:
- mongodb
- redis-server

View File

@ -199,7 +199,6 @@ AbstractClass.create = function (data, callback) {
this._adapter().create(modelName, this.constructor._forDB(data), function (err, id) {
if (id) {
defineReadonlyProp(obj, 'id', id);
addToCache(this.constructor, obj);
}
done.call(this, function () {
if (callback) {
@ -238,9 +237,6 @@ AbstractClass.upsert = AbstractClass.updateOrCreate = function upsert(data, call
} else {
obj = null;
}
if (obj) {
addToCache(Model, obj);
}
callback(err, obj);
});
} else {
@ -284,18 +280,9 @@ AbstractClass.find = function find(id, cb) {
this.schema.adapter.find(this.modelName, id, function (err, data) {
var obj = null;
if (data) {
var cached = getCached(this, data.id);
if (cached) {
obj = cached;
substractDirtyAttributes(obj, data);
// maybe just obj._initProperties(data); instead of
this.prototype._initProperties.call(obj, data);
} else {
data.id = id;
obj = new this();
obj._initProperties(data, false);
addToCache(this, id);
}
}
cb(err, obj);
}.bind(this));
@ -326,25 +313,17 @@ AbstractClass.all = function all(params, cb) {
}
var constr = this;
this.schema.adapter.all(this.modelName, params, function (err, data) {
var collection = null, cache = {};
var collection = null;
if (data && data.map) {
collection = new Array();
data.forEach(function (d, i) {
collection.__defineGetter__(i, function () {
if (cache[i]) {
return cache[i];
}
var obj = new constr;
obj._initProperties(d, false);
cache[i] = obj;
return obj;
});
data[i] = obj;
});
if (data && data.countBeforeLimit) {
collection.countBeforeLimit = data.countBeforeLimit;
}
collection.length = data.length;
cb(err, collection);
cb(err, data);
}
else
cb(err, []);
@ -387,7 +366,6 @@ AbstractClass.destroyAll = function destroyAll(cb) {
if (stillConnecting(this.schema, this, arguments)) return;
this.schema.adapter.destroyAll(this.modelName, function (err) {
clearCache(this);
cb(err);
}.bind(this));
};
@ -556,7 +534,6 @@ AbstractClass.prototype.destroy = function (cb) {
this.trigger('destroy', function (destroyed) {
this._adapter().destroy(this.constructor.modelName, this.id, function (err) {
removeFromCache(this.constructor, this.id);
destroyed(function () {
if(cb) cb(err);
});
@ -660,8 +637,6 @@ AbstractClass.prototype.propertyChanged = function propertyChanged(attr) {
AbstractClass.prototype.reload = function reload(callback) {
if (stillConnecting(this.constructor.schema, this, arguments)) return;
var obj = getCached(this.constructor, this.id);
if (obj) obj.reset();
this.constructor.find(this.id, callback);
};
@ -934,60 +909,3 @@ function defineReadonlyProp(obj, key, value) {
});
}
/**
* Add object to cache
*/
function addToCache(constr, obj) {
return;
touchCache(constr, obj.id);
constr.cache[obj.id] = obj;
}
/**
* Renew object position in LRU cache index
*/
function touchCache(constr, id) {
var cacheLimit = constr.CACHE_LIMIT || DEFAULT_CACHE_LIMIT;
var ind = constr.mru.indexOf(id);
if (~ind) constr.mru.splice(ind, 1);
if (constr.mru.length >= cacheLimit * 2) {
for (var i = 0; i < cacheLimit;i += 1) {
delete constr.cache[constr.mru[i]];
}
constr.mru.splice(0, cacheLimit);
}
}
/**
* Retrieve cached object
*/
function getCached(constr, id) {
if (id) touchCache(constr, id);
return id && constr.cache[id];
}
/**
* Clear cache (fully)
*
* removes both cache and LRU index
*
* @param {Class} constr - class constructor
*/
function clearCache(constr) {
constr.cache = {};
constr.mru = [];
}
/**
* Remove object from cache
*
* @param {Class} constr
* @param {id} id
*/
function removeFromCache(constr, id) {
var ind = constr.mru.indexOf(id);
if (!~ind) constr.mru.splice(ind, 1);
delete constr.cache[id];
}

View File

@ -1,7 +1,7 @@
{
"name": "jugglingdb",
"description": "ORM for every database: redis, mysql, neo4j, mongodb, postgres, sqlite",
"version": "0.1.21",
"version": "0.1.23-pre",
"author": "Anatoliy Chakkaev <rpm1602@gmail.com>",
"contributors": [
{ "name": "Anatoliy Chakkaev", "email": "rpm1602@gmail.com" },