forked from GitHub/dbot
performance enhancements to resolveUser [Close #570]
This commit is contained in:
parent
36aae7cad1
commit
31f32ca8da
@ -1,9 +1,6 @@
|
|||||||
var _ = require('underscore')._,
|
var _ = require('underscore')._,
|
||||||
uuid = require('node-uuid'),
|
uuid = require('node-uuid'),
|
||||||
databank = require('databank'),
|
databank = require('databank');
|
||||||
AlreadyExistsError = databank.AlreadyExistsError,
|
|
||||||
NoSuchThingError = databank.NoSuchThingError,
|
|
||||||
NotImplementedError = databank.NotImplementedError;
|
|
||||||
|
|
||||||
var api = function(dbot) {
|
var api = function(dbot) {
|
||||||
var escapeRegexen = function(str) {
|
var escapeRegexen = function(str) {
|
||||||
@ -13,16 +10,16 @@ var api = function(dbot) {
|
|||||||
var api = {
|
var api = {
|
||||||
// Return a user record given a primary nick or an alias
|
// Return a user record given a primary nick or an alias
|
||||||
'resolveUser': function(server, nick, callback) {
|
'resolveUser': function(server, nick, callback) {
|
||||||
var user = false;
|
if(_.has(this.userCache[server], nick)) {
|
||||||
|
this.api.getUser(this.userCache[server][nick], callback);
|
||||||
|
} else {
|
||||||
this.db.search('users', { 'server': server }, function(result) {
|
this.db.search('users', { 'server': server }, function(result) {
|
||||||
if(result.primaryNick == nick || _.include(result.aliases, nick)) {
|
if(result.primaryNick == nick || _.include(result.aliases, nick)) {
|
||||||
user = result;
|
this.userCache[server][nick] = result.id;
|
||||||
|
return callback(result);
|
||||||
}
|
}
|
||||||
}, function(err) {
|
}.bind(this), function(err) {});
|
||||||
if(!err) {
|
|
||||||
callback(user);
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Return many user records given primary nicks of aliases
|
// Return many user records given primary nicks of aliases
|
||||||
@ -47,16 +44,10 @@ var api = function(dbot) {
|
|||||||
|
|
||||||
// Return a user record given a UUID
|
// Return a user record given a UUID
|
||||||
'getUser': function(uuid, callback) {
|
'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) {
|
this.db.read('users', uuid, function(err, user) {
|
||||||
if(err) user = false;
|
if(err) user = false;
|
||||||
callback(user);
|
callback(user);
|
||||||
});
|
});
|
||||||
}
|
|
||||||
}.bind(this));
|
|
||||||
},
|
},
|
||||||
|
|
||||||
'resolveChannel': function(server, channelName, callback) {
|
'resolveChannel': function(server, channelName, callback) {
|
||||||
|
@ -8,6 +8,9 @@ var _ = require('underscore')._,
|
|||||||
|
|
||||||
var users = function(dbot) {
|
var users = function(dbot) {
|
||||||
this.userCache = {};
|
this.userCache = {};
|
||||||
|
_.each(dbot.config.servers, function(v, k) {
|
||||||
|
this.userCache[k] = {};
|
||||||
|
}.bind(this));
|
||||||
|
|
||||||
/*** Internal API ***/
|
/*** Internal API ***/
|
||||||
this.internalAPI = {
|
this.internalAPI = {
|
||||||
|
Loading…
Reference in New Issue
Block a user