- added views to do .all queries, it speeds up the query.

This commit is contained in:
Muneeb Samuels 2012-11-04 22:22:00 +02:00
parent 53272e6fd6
commit d248de7f9d
1 changed files with 20 additions and 13 deletions

View File

@ -260,24 +260,31 @@ CradleAdapter.prototype.count = function(model, callback, where) {
}; };
CradleAdapter.prototype.models = function(model, filter, callback, func) { CradleAdapter.prototype.models = function(model, filter, callback, func) {
var limit = 99999999; // maybe there is a better way to do this? var limit = 200;
var skip = 0; var skip = 0;
if (filter != null) { if (filter != null) {
limit = filter.limit || limit; limit = filter.limit || limit;
skip = filter.skip ||skip; skip = filter.skip ||skip;
} }
this.client.all( var self = this;
{include_docs:true, limit: limit, skip: skip},
errorHandler(callback, function(res, cb) {
var docs = res.map(function(doc) {
return idealize(doc);
});
var filtered = filtering(docs, model, filter, this._models)
func ? func(filtered, cb) : cb(filtered); self.client.save('_design/'+model, {
}.bind(this)) views : {
); all : {
map : 'function(doc) { if (doc.nature == "'+model+'") { emit(doc._id, doc); } }'
}
}
}, function() {
self.client.view(model+'/all', {include_docs:true, limit:limit, skip:skip}, errorHandler(callback, function(res, cb) {
var docs = res.map(function(doc) {
return idealize(doc);
});
var filtered = filtering(docs, model, filter, this._models)
func ? func(filtered, cb) : cb(filtered);
}.bind(self)));
});
}; };
CradleAdapter.prototype.all = function(model, filter, callback) { CradleAdapter.prototype.all = function(model, filter, callback) {