From 488bc68e05a2a60f41b20c078f5ce5e8dc19c9e1 Mon Sep 17 00:00:00 2001 From: Anatoliy Chakkaev Date: Sat, 13 Oct 2012 18:25:50 +0400 Subject: [PATCH] Optimize collection --- lib/abstract-class.js | 22 +++++++--------------- package.json | 4 ++-- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/lib/abstract-class.js b/lib/abstract-class.js index f9655504..e82329f5 100644 --- a/lib/abstract-class.js +++ b/lib/abstract-class.js @@ -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; diff --git a/package.json b/package.json index 2228f695..cf652e3c 100644 --- a/package.json +++ b/package.json @@ -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 ", "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"