Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Lazy load reds search

  • Loading branch information...
commit e910aea6c169b7a55c81a9df94d8fa3044c8f828 1 parent b2cd5d3
@davidwood davidwood authored tj committed
Showing with 22 additions and 7 deletions.
  1. +11 −3 lib/http/routes/json.js
  2. +11 −4 lib/queue/job.js
View
14 lib/http/routes/json.js
@@ -18,7 +18,15 @@ var Queue = require('../../kue')
* 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:
@@ -171,7 +179,7 @@ exports.updateState = 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 });
res.send(ids);
});
@@ -216,4 +224,4 @@ function get(obj) {
}
return _;
};
-}
+}
View
15 lib/queue/job.js
@@ -25,7 +25,14 @@ exports = module.exports = Job;
* 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.
@@ -400,7 +407,7 @@ Job.prototype.attempts = function(n){
Job.prototype.remove = function(fn){
this.removeState();
- search.remove(this.id);
+ getSearch().remove(this.id);
this.client.del('q:job:' + this.id, fn || noop);
return this;
};
@@ -560,5 +567,5 @@ Job.prototype.update = function(fn){
this.set('data', json, fn);
// search data
- search.index(json, this.id);
-};
+ getSearch().index(json, this.id);
+};
Please sign in to comment.
Something went wrong with that request. Please try again.