Skip to content

Commit

Permalink
Lazy load reds search
Browse files Browse the repository at this point in the history
  • Loading branch information
davidwood authored and tj committed Aug 10, 2011
1 parent b2cd5d3 commit e910aea
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
14 changes: 11 additions & 3 deletions lib/http/routes/json.js
Expand Up @@ -18,7 +18,15 @@ var Queue = require('../../kue')
* Search instance. * Search instance.
*/ */


var search = reds.createSearch('q:search'); var search;
function getSearch() {
if (!search) {
reds.createClient = require('../../redis').createClient;
search = reds.createSearch('q:search');
}
return search;
};



/** /**
* Get statistics including: * Get statistics including:
Expand Down Expand Up @@ -171,7 +179,7 @@ exports.updateState = function(req, res){
*/ */


exports.search = function(req, res){ exports.search = function(req, res){
search.query(req.query.q, function(err, ids){ getSearch().query(req.query.q, function(err, ids){
if (err) return res.send({ error: err.message }); if (err) return res.send({ error: err.message });
res.send(ids); res.send(ids);
}); });
Expand Down Expand Up @@ -216,4 +224,4 @@ function get(obj) {
} }
return _; return _;
}; };
} }
15 changes: 11 additions & 4 deletions lib/queue/job.js
Expand Up @@ -25,7 +25,14 @@ exports = module.exports = Job;
* Search instance. * Search instance.
*/ */


var search = reds.createSearch('q:search'); var search;
function getSearch() {
if (!search) {
reds.createClient = require('../redis').createClient;
search = reds.createSearch('q:search');
}
return search;
};


/** /**
* Default job priority map. * Default job priority map.
Expand Down Expand Up @@ -400,7 +407,7 @@ Job.prototype.attempts = function(n){


Job.prototype.remove = function(fn){ Job.prototype.remove = function(fn){
this.removeState(); this.removeState();
search.remove(this.id); getSearch().remove(this.id);
this.client.del('q:job:' + this.id, fn || noop); this.client.del('q:job:' + this.id, fn || noop);
return this; return this;
}; };
Expand Down Expand Up @@ -560,5 +567,5 @@ Job.prototype.update = function(fn){
this.set('data', json, fn); this.set('data', json, fn);


// search data // search data
search.index(json, this.id); getSearch().index(json, this.id);
}; };

0 comments on commit e910aea

Please sign in to comment.