Skip to content

Commit

Permalink
minor performance enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
polonel committed Jul 27, 2016
1 parent 887fa51 commit 3337f03
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 36 deletions.
26 changes: 13 additions & 13 deletions src/cache/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ truCache.init = function(callback) {
winston.debug('Cache Loaded');
restartRefreshClock();

callback();
return callback();
});
};

Expand All @@ -81,10 +81,10 @@ truCache.refreshCache = function(callback) {
async.waterfall([
function(done) {
var ticketSchema = require('../models/ticket');
ticketSchema.getAll(function(err, tickets) {
ticketSchema.getAllNoPopulate(function(err, tickets) {
if (err) return done(err);

done(null, tickets);
return done(null, tickets);
});
},

Expand Down Expand Up @@ -126,7 +126,7 @@ truCache.refreshCache = function(callback) {
cache.set('tickets:overview:lifetime:responseTime', stats.lifetime.avgResponse, 3600);
cache.set('tickets:overview:lifetime:graphData', stats.lifetime.graphData, 3600);

done();
return done();
});
},
function(done) {
Expand All @@ -138,7 +138,7 @@ truCache.refreshCache = function(callback) {

cache.set('tags:30:usage', stats, 3600);

c();
return c();
});
},
function(c) {
Expand All @@ -147,7 +147,7 @@ truCache.refreshCache = function(callback) {

cache.set('tags:60:usage', stats, 3600);

c();
return c();
});
},
function(c) {
Expand All @@ -156,7 +156,7 @@ truCache.refreshCache = function(callback) {

cache.set('tags:90:usage', stats, 3600);

c();
return c();
});
},
function(c) {
Expand All @@ -165,7 +165,7 @@ truCache.refreshCache = function(callback) {

cache.set('tags:180:usage', stats, 3600);

c();
return c();
});
},
function(c) {
Expand All @@ -174,7 +174,7 @@ truCache.refreshCache = function(callback) {

cache.set('tags:365:usage', stats, 3600);

c();
return c();
});
},
function(c) {
Expand All @@ -183,11 +183,11 @@ truCache.refreshCache = function(callback) {

cache.set('tags:0:usage', stats, 3600);

c();
return c();
});
}
], function(err) {
done(err);
return done(err);
});
},
function(done) {
Expand All @@ -200,11 +200,11 @@ truCache.refreshCache = function(callback) {
cache.set('quickstats:mostAssignee', stats.mostAssignee, 3600);
cache.set('quickstats:mostActiveTicket', stats.mostActiveTicket, 3600);

done();
return done();
});
}
], function(err) {
cb(err);
return cb(err);
});
}

Expand Down
22 changes: 11 additions & 11 deletions src/cache/quickStats.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,50 +40,50 @@ var init = function(tickets, callback) {
function(done) {
if (tickets) {
$tickets = tickets;
done();
return done();
} else {
ticketSchema.getAll(function(err, tickets) {
if (err) return done(err);

$tickets = tickets;

done();
return done();
});
}
},
function(done) {
buildMostRequester($tickets, function(result) {
obj.mostRequester = _.first(result);

done();
return done();
});
},
function(done) {
buildMostComments($tickets, function(result) {
obj.mostCommenter = _.first(result);

done();
return done();
});
},
function(done) {
buildMostAssignee($tickets, function(result) {
obj.mostAssignee = _.first(result);

done();
return done();
});
},
function(done) {
buildMostActiveTicket($tickets, function(result) {
obj.mostActiveTicket = _.first(result);

done();
return done();
});
}

], function(err) {
if (err) return callback(err);

callback(null, obj);
return callback(null, obj);
});
};

Expand All @@ -107,7 +107,7 @@ function buildMostRequester(ticketArray, callback) {
return { name: k, value: v};
});

callback(r);
return callback(r);
}

function buildMostComments(ticketArray, callback) {
Expand All @@ -132,7 +132,7 @@ function buildMostComments(ticketArray, callback) {
return { name: k, value: v};
});

callback(c);
return callback(c);
}

function buildMostAssignee(ticketArray, callback) {
Expand All @@ -159,7 +159,7 @@ function buildMostAssignee(ticketArray, callback) {
return { name: k, value: v};
});

callback(a);
return callback(a);
}

function buildMostActiveTicket(ticketArray, callback) {
Expand All @@ -169,7 +169,7 @@ function buildMostActiveTicket(ticketArray, callback) {

tickets = _.sortBy(tickets, 'cSize').reverse();

callback(tickets);
return callback(tickets);
}

module.exports = init;
17 changes: 12 additions & 5 deletions src/cache/tagStats.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,22 @@ var init = function(tickets, timespan, callback) {
async.series([
function(done) {
if (tickets) {
$tickets = tickets;
done();
ticketSchema.populate(tickets, {path: 'tags'}, function(err, _tickets) {
if (err) return done(err);

$tickets = _tickets;
return done();
});
} else {
ticketSchema.getAll(function(err, tickets) {
ticketSchema.getAllNoPopulate(function(err, tickets) {
if (err) return done(err);
ticketSchema.populate(tickets, {path: 'tags'}, function(err, _tickets) {
if (err) return done(err);

$tickets = tickets;
$tickets = _tickets;

done();
return done();
});
});
}
},
Expand Down
9 changes: 4 additions & 5 deletions src/cache/ticketStats.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ var init = function(tickets, callback) {
e60 = today.clone().subtract(60, 'd'),
e90 = today.clone().subtract(90, 'd'),
e180 = today.clone().subtract(180, 'd'),
e365 = today.clone().subtract(365, 'd'),
e36500 = today.clone().subtract(36500, 'd');
e365 = today.clone().subtract(365, 'd');

async.series({
allTickets: function(c) {
Expand All @@ -47,7 +46,7 @@ var init = function(tickets, callback) {

c();
} else {
ticketSchema.getAll(function(err, tickets) {
ticketSchema.getAllNoPopulate(function(err, tickets) {
if (err) return c(err);

$tickets = tickets;
Expand Down Expand Up @@ -235,7 +234,7 @@ function buildAvgResponse(ticketArray, callback) {

//Next Event Loop - [email protected]
async.setImmediate(function() {
callback();
return callback();
});

}, function (err) {
Expand All @@ -247,7 +246,7 @@ function buildAvgResponse(ticketArray, callback) {
var tvt = moment.duration(Math.round(ticketAvgTotal / _.size($ticketAvg)), 'seconds').asHours();
cbObj.avgResponse = Math.floor(tvt);

callback(cbObj);
return callback(cbObj);
});
}

Expand Down
4 changes: 2 additions & 2 deletions src/controllers/api/v1/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ api_groups.deleteGroup = function(req, res) {
return next('Error: Cannot delete a group with tickets.');
}

next();
return next();
});
},
function(next) {
Expand All @@ -255,7 +255,7 @@ api_groups.deleteGroup = function(req, res) {
group.remove(function(err, success) {
if (err) return next('Error: ' + err.message);

next(null, success);
return next(null, success);
});
});
}
Expand Down
7 changes: 7 additions & 0 deletions src/models/ticket.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,13 @@ ticketSchema.statics.getAll = function(callback) {
return q.exec(callback);
};

ticketSchema.statics.getAllNoPopulate = function(callback) {
var self = this;
var q = self.model(COLLECTION).find({deleted: false}).sort({'status': 1});

return q.exec(callback);
};

ticketSchema.statics.getAllByStatus = function(status, callback) {
var self = this;

Expand Down

0 comments on commit 3337f03

Please sign in to comment.