Last active
May 23, 2016 18:23
-
-
Save sampaiodiego/8e559988093989a9cde1bce411cb3929 to your computer and use it in GitHub Desktop.
Enter on a room (for example: https://demo.rocket.chat/channel/general) and run the entire code from the browser console.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var uid = Meteor.userId(); | |
var rid = Session.get('openedRoom'); | |
var roles = _.union((ref = UserRoles.findOne(uid)) != null ? ref.roles : void 0, (ref1 = RoomRoles.findOne({ | |
'u._id': uid, | |
rid: rid | |
})) != null ? ref1.roles : void 0); | |
var f2 = function() { | |
var ref, ref1; | |
return RocketChat.models.Roles.find({ | |
_id: { | |
$in: roles | |
}, | |
description: { | |
$exists: 1 | |
} | |
}, { | |
fields: { | |
description: 1 | |
} | |
}).fetch(); | |
}; | |
var f1 = function() { | |
var ref, ref1; | |
return _.compact(_.map(roles, function(role) { | |
var ref2; | |
return (ref2 = RocketChat.models.Roles.findOne({ | |
_id: role, | |
description: { | |
$exists: 1 | |
} | |
})) != null ? ref2.description : void 0; | |
})); | |
}; | |
console.log('f1 ->',f1()); | |
console.log('f2 ->',f2()); | |
var results = []; | |
var start = new Date(); | |
for (var i = 0; i < 10000; i++) { f1(); }; | |
var end = new Date(); | |
results.push(end - start); | |
var start = new Date(); | |
for (var i = 0; i < 10000; i++) { f2(); }; | |
var end = new Date(); | |
results.push(end - start); | |
console.log(results); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment