3
0
mirror of https://github.com/reality/dbot.git synced 2024-11-23 20:39:25 +01:00

performance enhancements to resolveUser [Close #570]

This commit is contained in:
reality 2013-08-25 14:56:00 +00:00
parent 36aae7cad1
commit 31f32ca8da
2 changed files with 18 additions and 24 deletions

View File

@ -1,9 +1,6 @@
var _ = require('underscore')._,
uuid = require('node-uuid'),
databank = require('databank'),
AlreadyExistsError = databank.AlreadyExistsError,
NoSuchThingError = databank.NoSuchThingError,
NotImplementedError = databank.NotImplementedError;
databank = require('databank');
var api = function(dbot) {
var escapeRegexen = function(str) {
@ -13,16 +10,16 @@ var api = function(dbot) {
var api = {
// Return a user record given a primary nick or an alias
'resolveUser': function(server, nick, callback) {
var user = false;
this.db.search('users', { 'server': server }, function(result) {
if(result.primaryNick == nick || _.include(result.aliases, nick)) {
user = result;
}
}, function(err) {
if(!err) {
callback(user);
}
});
if(_.has(this.userCache[server], nick)) {
this.api.getUser(this.userCache[server][nick], callback);
} else {
this.db.search('users', { 'server': server }, function(result) {
if(result.primaryNick == nick || _.include(result.aliases, nick)) {
this.userCache[server][nick] = result.id;
return callback(result);
}
}.bind(this), function(err) {});
}
},
// Return many user records given primary nicks of aliases
@ -47,16 +44,10 @@ var api = function(dbot) {
// Return a user record given a UUID
'getUser': function(uuid, callback) {
this.db.read('user_redirs', uuid, function(err, id) {
if(!err) {
this.api.getUser(id, callback);
} else {
this.db.read('users', uuid, function(err, user) {
if(err) user = false;
callback(user);
});
}
}.bind(this));
this.db.read('users', uuid, function(err, user) {
if(err) user = false;
callback(user);
});
},
'resolveChannel': function(server, channelName, callback) {

View File

@ -8,6 +8,9 @@ var _ = require('underscore')._,
var users = function(dbot) {
this.userCache = {};
_.each(dbot.config.servers, function(v, k) {
this.userCache[k] = {};
}.bind(this));
/*** Internal API ***/
this.internalAPI = {