Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

console.time

  • Loading branch information...
commit e6244e030feb721a75e0b55dd769fe9026f2b62b 1 parent 24a2a3c
@toantran authored
Showing with 27 additions and 12 deletions.
  1. +15 −6 coffee/services/user.coffee
  2. +12 −6 services/user.js
View
21 coffee/services/user.coffee
@@ -706,12 +706,14 @@ exports.getFullUser = (userid, callback = ->) ->
console.assert userid, 'userid cannot be null or 0'
throw 'userid cannot be null or 0' unless userid
+ console.time 'load userbyid'
utils.execute( newUserRepo.getById, userid ) # load user
.then (err, @user, cb = ->) =>
- console.log 'load team'
+ console.timeEnd 'load userbyid'
# load team
return callback( err ) if err
+ console.time 'load team'
if @user?.team?
try
teamRepo.getById @user?.team?._id, cb
@@ -721,13 +723,14 @@ exports.getFullUser = (userid, callback = ->) ->
else
cb()
.then (err, @team, cb = ->) =>
- console.log 'load posts'
+ console.timeEnd 'load team'
# Load posts
return callback( err ) if err
+
+ console.time 'load posts'
@user?.team = @team
if @user?.posts? and @user?.posts?.length
- console.log 'load posts begin'
try
postGen = require './post'
postGen.init()
@@ -740,7 +743,7 @@ exports.getFullUser = (userid, callback = ->) ->
cb null, null
.then (err, fullposts, cb = ->) =>
- console.log 'load invites'
+ console.timeEnd 'load posts'
if fullposts?
posts = (post for post in fullposts when post?.desc?)
else
@@ -752,6 +755,8 @@ exports.getFullUser = (userid, callback = ->) ->
@user?.posts = posts
# Load invites
+
+ console.time 'load invites'
try
if @user?.invites and @user?.invites?.length
utils.mapAsync @user?.invites, loadFullInvite, cb
@@ -761,12 +766,14 @@ exports.getFullUser = (userid, callback = ->) ->
console.trace e
cb e
.then (err, invites, cb = ->) =>
- console.log 'load challenges'
+ console.timeEnd 'load invites'
return callback( err ) if err
@user?.invites = invites
# Load challenges
+
+ console.time 'load challenges'
if @team?.challenges?.length
loadChallenge = (challenge, loadChallengeCallback = ->) ->
@@ -778,13 +785,14 @@ exports.getFullUser = (userid, callback = ->) ->
else
cb null, null
.then ( err, challenges, cb = ->) =>
- console.log 'load matches'
+ console.timeEnd 'load challenges'
@team?.challenges = challenges
@user?.challenges = challenges
allmatches = @team?.matches
# Load pending matches
matches = (match for match in allmatches when match?.status is 'pending') if allmatches?
+ console.time 'load matches'
if matches?.length
matchsvc = require './match'
async = require 'async'
@@ -822,6 +830,7 @@ exports.getFullUser = (userid, callback = ->) ->
else
callback null, @user
.then ( err, matches, cb = ->) =>
+ console.timeEnd 'load matches'
console.log 'load end'
@user.matches = matches
callback null, @user
View
18 services/user.js
@@ -913,12 +913,14 @@
if (callback == null) callback = function() {};
console.assert(userid, 'userid cannot be null or 0');
if (!userid) throw 'userid cannot be null or 0';
+ console.time('load userbyid');
return utils.execute(newUserRepo.getById, userid).then(function(err, user, cb) {
var _ref, _ref2, _ref3;
_this.user = user;
if (cb == null) cb = function() {};
- console.log('load team');
+ console.timeEnd('load userbyid');
if (err) return callback(err);
+ console.time('load team');
if (((_ref = _this.user) != null ? _ref.team : void 0) != null) {
try {
return teamRepo.getById((_ref2 = _this.user) != null ? (_ref3 = _ref2.team) != null ? _ref3._id : void 0 : void 0, cb);
@@ -933,11 +935,11 @@
var postGen, _ref, _ref2, _ref3, _ref4, _ref5;
_this.team = team;
if (cb == null) cb = function() {};
- console.log('load posts');
+ console.timeEnd('load team');
if (err) return callback(err);
+ console.time('load posts');
if ((_ref = _this.user) != null) _ref.team = _this.team;
if ((((_ref2 = _this.user) != null ? _ref2.posts : void 0) != null) && ((_ref3 = _this.user) != null ? (_ref4 = _ref3.posts) != null ? _ref4.length : void 0 : void 0)) {
- console.log('load posts begin');
try {
postGen = require('./post');
postGen.init();
@@ -953,7 +955,7 @@
}).then(function(err, fullposts, cb) {
var post, posts, _ref, _ref2, _ref3, _ref4, _ref5;
if (cb == null) cb = function() {};
- console.log('load invites');
+ console.timeEnd('load posts');
if (fullposts != null) {
posts = (function() {
var _i, _len, _results;
@@ -973,6 +975,7 @@
});
}
if ((_ref = _this.user) != null) _ref.posts = posts;
+ console.time('load invites');
try {
if (((_ref2 = _this.user) != null ? _ref2.invites : void 0) && ((_ref3 = _this.user) != null ? (_ref4 = _ref3.invites) != null ? _ref4.length : void 0 : void 0)) {
return utils.mapAsync((_ref5 = _this.user) != null ? _ref5.invites : void 0, loadFullInvite, cb);
@@ -986,9 +989,10 @@
}).then(function(err, invites, cb) {
var _ref, _ref2, _ref3, _ref4;
if (cb == null) cb = function() {};
- console.log('load challenges');
+ console.timeEnd('load invites');
if (err) return callback(err);
if ((_ref = _this.user) != null) _ref.invites = invites;
+ console.time('load challenges');
if ((_ref2 = _this.team) != null ? (_ref3 = _ref2.challenges) != null ? _ref3.length : void 0 : void 0) {
loadChallenge = function(challenge, loadChallengeCallback) {
if (loadChallengeCallback == null) loadChallengeCallback = function() {};
@@ -1004,7 +1008,7 @@
}).then(function(err, challenges, cb) {
var allmatches, async, match, matches, matchsvc, _ref, _ref2, _ref3;
if (cb == null) cb = function() {};
- console.log('load matches');
+ console.timeEnd('load challenges');
if ((_ref = _this.team) != null) _ref.challenges = challenges;
if ((_ref2 = _this.user) != null) _ref2.challenges = challenges;
allmatches = (_ref3 = _this.team) != null ? _ref3.matches : void 0;
@@ -1021,6 +1025,7 @@
return _results;
})();
}
+ console.time('load matches');
if (matches != null ? matches.length : void 0) {
matchsvc = require('./match');
async = require('async');
@@ -1077,6 +1082,7 @@
}
}).then(function(err, matches, cb) {
if (cb == null) cb = function() {};
+ console.timeEnd('load matches');
console.log('load end');
_this.user.matches = matches;
return callback(null, _this.user);
Please sign in to comment.
Something went wrong with that request. Please try again.