Permalink
Browse files

Optimize collection

  • Loading branch information...
1 parent 1ec419a commit 488bc68e05a2a60f41b20c078f5ce5e8dc19c9e1 @1602 committed Oct 13, 2012
Showing with 9 additions and 17 deletions.
  1. +7 −15 lib/abstract-class.js
  2. +2 −2 package.json
View
@@ -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
@@ -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"

0 comments on commit 488bc68

Please sign in to comment.