Optimize collection

This commit is contained in:
Anatoliy Chakkaev 2012-10-13 18:25:50 +04:00
parent 1ec419aa42
commit 488bc68e05
2 changed files with 9 additions and 17 deletions

View File

@ -328,22 +328,14 @@ AbstractClass.all = function all(params, cb) {
this.schema.adapter.all(this.modelName, params, function (err, data) {
var collection = null;
if (data && data.map) {
collection = data.map(function (d) {
var obj = null;
// do not create different instances for the same object
var cached = d && getCached(constr, d.id);
if (cached) {
obj = cached;
// keep dirty attributes untouthed (remove from dataset)
substractDirtyAttributes(obj, d);
// maybe just obj._initProperties(d);
constr.prototype._initProperties.call(obj, d);
} else {
obj = new constr;
collection = new Array();
data.forEach(function (d, i) {
collection.__defineGetter__(i, function () {
var obj = new constr;
obj._initProperties(d, false);
if (obj.id) addToCache(constr, obj);
}
return obj;
collection[i] = obj;
return obj;
});
});
if (data && data.countBeforeLimit) {
collection.countBeforeLimit = data.countBeforeLimit;

View File

@ -1,7 +1,7 @@
{
"name": "jugglingdb",
"description": "ORM for every database: redis, mysql, neo4j, mongodb, postgres, sqlite",
"version": "0.1.20",
"version": "0.1.21",
"author": "Anatoliy Chakkaev <rpm1602@gmail.com>",
"contributors": [
{ "name": "Anatoliy Chakkaev", "email": "rpm1602@gmail.com" },
@ -20,7 +20,7 @@
},
"main": "index.js",
"scripts": {
"test": "EXCEPT=cradle,neo4j nodeunit test/*_test*"
"test": "EXCEPT=cradle nodeunit test/*_test*"
},
"engines": [
"node >= 0.4.12"