Skip to content

Commit

Permalink
console.time
Browse files Browse the repository at this point in the history
  • Loading branch information
toantran committed Mar 28, 2012
1 parent 24a2a3c commit e6244e0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
21 changes: 15 additions & 6 deletions coffee/services/user.coffee
Expand Up @@ -706,12 +706,14 @@ exports.getFullUser = (userid, callback = ->) ->
console.assert userid, 'userid cannot be null or 0' console.assert userid, 'userid cannot be null or 0'
throw 'userid cannot be null or 0' unless userid throw 'userid cannot be null or 0' unless userid


console.time 'load userbyid'
utils.execute( newUserRepo.getById, userid ) # load user utils.execute( newUserRepo.getById, userid ) # load user
.then (err, @user, cb = ->) => .then (err, @user, cb = ->) =>
console.log 'load team' console.timeEnd 'load userbyid'
# load team # load team
return callback( err ) if err return callback( err ) if err


console.time 'load team'
if @user?.team? if @user?.team?
try try
teamRepo.getById @user?.team?._id, cb teamRepo.getById @user?.team?._id, cb
Expand All @@ -721,13 +723,14 @@ exports.getFullUser = (userid, callback = ->) ->
else else
cb() cb()
.then (err, @team, cb = ->) => .then (err, @team, cb = ->) =>
console.log 'load posts' console.timeEnd 'load team'
# Load posts # Load posts
return callback( err ) if err return callback( err ) if err

console.time 'load posts'
@user?.team = @team @user?.team = @team


if @user?.posts? and @user?.posts?.length if @user?.posts? and @user?.posts?.length
console.log 'load posts begin'
try try
postGen = require './post' postGen = require './post'
postGen.init() postGen.init()
Expand All @@ -740,7 +743,7 @@ exports.getFullUser = (userid, callback = ->) ->
cb null, null cb null, null


.then (err, fullposts, cb = ->) => .then (err, fullposts, cb = ->) =>
console.log 'load invites' console.timeEnd 'load posts'
if fullposts? if fullposts?
posts = (post for post in fullposts when post?.desc?) posts = (post for post in fullposts when post?.desc?)
else else
Expand All @@ -752,6 +755,8 @@ exports.getFullUser = (userid, callback = ->) ->


@user?.posts = posts @user?.posts = posts
# Load invites # Load invites

console.time 'load invites'
try try
if @user?.invites and @user?.invites?.length if @user?.invites and @user?.invites?.length
utils.mapAsync @user?.invites, loadFullInvite, cb utils.mapAsync @user?.invites, loadFullInvite, cb
Expand All @@ -761,12 +766,14 @@ exports.getFullUser = (userid, callback = ->) ->
console.trace e console.trace e
cb e cb e
.then (err, invites, cb = ->) => .then (err, invites, cb = ->) =>
console.log 'load challenges' console.timeEnd 'load invites'
return callback( err ) if err return callback( err ) if err


@user?.invites = invites @user?.invites = invites


# Load challenges # Load challenges

console.time 'load challenges'
if @team?.challenges?.length if @team?.challenges?.length


loadChallenge = (challenge, loadChallengeCallback = ->) -> loadChallenge = (challenge, loadChallengeCallback = ->) ->
Expand All @@ -778,13 +785,14 @@ exports.getFullUser = (userid, callback = ->) ->
else else
cb null, null cb null, null
.then ( err, challenges, cb = ->) => .then ( err, challenges, cb = ->) =>
console.log 'load matches' console.timeEnd 'load challenges'
@team?.challenges = challenges @team?.challenges = challenges
@user?.challenges = challenges @user?.challenges = challenges
allmatches = @team?.matches allmatches = @team?.matches
# Load pending matches # Load pending matches
matches = (match for match in allmatches when match?.status is 'pending') if allmatches? matches = (match for match in allmatches when match?.status is 'pending') if allmatches?


console.time 'load matches'
if matches?.length if matches?.length
matchsvc = require './match' matchsvc = require './match'
async = require 'async' async = require 'async'
Expand Down Expand Up @@ -822,6 +830,7 @@ exports.getFullUser = (userid, callback = ->) ->
else else
callback null, @user callback null, @user
.then ( err, matches, cb = ->) => .then ( err, matches, cb = ->) =>
console.timeEnd 'load matches'
console.log 'load end' console.log 'load end'
@user.matches = matches @user.matches = matches
callback null, @user callback null, @user
Expand Down
18 changes: 12 additions & 6 deletions services/user.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e6244e0

Please sign in to comment.