Proper collection caching
This commit is contained in:
parent
f59cf0ddbf
commit
f6d8b08631
|
@ -326,14 +326,17 @@ AbstractClass.all = function all(params, cb) {
|
|||
}
|
||||
var constr = this;
|
||||
this.schema.adapter.all(this.modelName, params, function (err, data) {
|
||||
var collection = null;
|
||||
var collection = null, cache = {};
|
||||
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);
|
||||
collection[i] = obj;
|
||||
cache[i] = obj;
|
||||
return obj;
|
||||
});
|
||||
});
|
||||
|
@ -535,7 +538,7 @@ AbstractClass.prototype.toObject = function (onlySchema) {
|
|||
};
|
||||
|
||||
AbstractClass.prototype.hasOwnProperty = function (prop) {
|
||||
return this.__data.hasOwnProperty(prop) ||
|
||||
return this.__data && this.__data.hasOwnProperty(prop) ||
|
||||
Object.getOwnPropertyNames(this).indexOf(prop) !== -1;
|
||||
};
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
},
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "EXCEPT=cradle nodeunit test/*_test*"
|
||||
"test": "EXCEPT=cradle,neo4j nodeunit test/*_test*"
|
||||
},
|
||||
"engines": [
|
||||
"node >= 0.4.12"
|
||||
|
|
Loading…
Reference in New Issue