Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Lazy load reds search

  • Loading branch information...
commit e910aea6c169b7a55c81a9df94d8fa3044c8f828 1 parent b2cd5d3
David Wood davidwood authored visionmedia committed

Showing 2 changed files with 22 additions and 7 deletions. Show diff stats Hide diff stats

  1. +11 3 lib/http/routes/json.js
  2. +11 4 lib/queue/job.js
14 lib/http/routes/json.js
@@ -18,7 +18,15 @@ var Queue = require('../../kue')
18 18 * Search instance.
19 19 */
20 20
21   -var search = reds.createSearch('q:search');
  21 +var search;
  22 +function getSearch() {
  23 + if (!search) {
  24 + reds.createClient = require('../../redis').createClient;
  25 + search = reds.createSearch('q:search');
  26 + }
  27 + return search;
  28 +};
  29 +
22 30
23 31 /**
24 32 * Get statistics including:
@@ -171,7 +179,7 @@ exports.updateState = function(req, res){
171 179 */
172 180
173 181 exports.search = function(req, res){
174   - search.query(req.query.q, function(err, ids){
  182 + getSearch().query(req.query.q, function(err, ids){
175 183 if (err) return res.send({ error: err.message });
176 184 res.send(ids);
177 185 });
@@ -216,4 +224,4 @@ function get(obj) {
216 224 }
217 225 return _;
218 226 };
219   -}
  227 +}
15 lib/queue/job.js
@@ -25,7 +25,14 @@ exports = module.exports = Job;
25 25 * Search instance.
26 26 */
27 27
28   -var search = reds.createSearch('q:search');
  28 +var search;
  29 +function getSearch() {
  30 + if (!search) {
  31 + reds.createClient = require('../redis').createClient;
  32 + search = reds.createSearch('q:search');
  33 + }
  34 + return search;
  35 +};
29 36
30 37 /**
31 38 * Default job priority map.
@@ -400,7 +407,7 @@ Job.prototype.attempts = function(n){
400 407
401 408 Job.prototype.remove = function(fn){
402 409 this.removeState();
403   - search.remove(this.id);
  410 + getSearch().remove(this.id);
404 411 this.client.del('q:job:' + this.id, fn || noop);
405 412 return this;
406 413 };
@@ -560,5 +567,5 @@ Job.prototype.update = function(fn){
560 567 this.set('data', json, fn);
561 568
562 569 // search data
563   - search.index(json, this.id);
564   -};
  570 + getSearch().index(json, this.id);
  571 +};

0 comments on commit e910aea

Please sign in to comment.
Something went wrong with that request. Please try again.