Optimize collection
This commit is contained in:
parent
1ec419aa42
commit
488bc68e05
|
@ -328,23 +328,15 @@ AbstractClass.all = function all(params, cb) {
|
||||||
this.schema.adapter.all(this.modelName, params, function (err, data) {
|
this.schema.adapter.all(this.modelName, params, function (err, data) {
|
||||||
var collection = null;
|
var collection = null;
|
||||||
if (data && data.map) {
|
if (data && data.map) {
|
||||||
collection = data.map(function (d) {
|
collection = new Array();
|
||||||
var obj = null;
|
data.forEach(function (d, i) {
|
||||||
// do not create different instances for the same object
|
collection.__defineGetter__(i, function () {
|
||||||
var cached = d && getCached(constr, d.id);
|
var obj = new constr;
|
||||||
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;
|
|
||||||
obj._initProperties(d, false);
|
obj._initProperties(d, false);
|
||||||
if (obj.id) addToCache(constr, obj);
|
collection[i] = obj;
|
||||||
}
|
|
||||||
return obj;
|
return obj;
|
||||||
});
|
});
|
||||||
|
});
|
||||||
if (data && data.countBeforeLimit) {
|
if (data && data.countBeforeLimit) {
|
||||||
collection.countBeforeLimit = data.countBeforeLimit;
|
collection.countBeforeLimit = data.countBeforeLimit;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "jugglingdb",
|
"name": "jugglingdb",
|
||||||
"description": "ORM for every database: redis, mysql, neo4j, mongodb, postgres, sqlite",
|
"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>",
|
"author": "Anatoliy Chakkaev <rpm1602@gmail.com>",
|
||||||
"contributors": [
|
"contributors": [
|
||||||
{ "name": "Anatoliy Chakkaev", "email": "rpm1602@gmail.com" },
|
{ "name": "Anatoliy Chakkaev", "email": "rpm1602@gmail.com" },
|
||||||
|
@ -20,7 +20,7 @@
|
||||||
},
|
},
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "EXCEPT=cradle,neo4j nodeunit test/*_test*"
|
"test": "EXCEPT=cradle nodeunit test/*_test*"
|
||||||
},
|
},
|
||||||
"engines": [
|
"engines": [
|
||||||
"node >= 0.4.12"
|
"node >= 0.4.12"
|
||||||
|
|
Loading…
Reference in New Issue