mirror of
https://github.com/reality/dbot.git
synced 2024-11-23 20:39:25 +01:00
some more efficiency improvements in users
This commit is contained in:
parent
31f32ca8da
commit
5cf79312f4
@ -10,15 +10,19 @@ var api = function(dbot) {
|
||||
var api = {
|
||||
// Return a user record given a primary nick or an alias
|
||||
'resolveUser': function(server, nick, callback) {
|
||||
var found = false;
|
||||
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);
|
||||
found = true;
|
||||
callback(result);
|
||||
}
|
||||
}.bind(this), function(err) {});
|
||||
}.bind(this), function(err) {
|
||||
if(!found) callback(false);
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -127,29 +127,18 @@ var users = function(dbot) {
|
||||
}.bind(this));
|
||||
}.bind(this);
|
||||
var checkUser = function(done) {
|
||||
var checkCurrentNick = function(user) {
|
||||
if(event.user != user.currentNick) {
|
||||
user.currentNick = event.user;
|
||||
this.db.save('users', user.id, user, function() {
|
||||
done(user);
|
||||
});
|
||||
this.api.resolveUser(event.server, event.user, function(user) {
|
||||
if(!user) {
|
||||
this.internalAPI.createUser(event.server, event.user, done);
|
||||
} else {
|
||||
done(user);
|
||||
}
|
||||
}.bind(this);
|
||||
|
||||
if(_.has(this.userCache, event.server) && _.has(this.userCache[event.server], event.user)) {
|
||||
this.api.getUser(this.userCache[event.server][event.user], checkCurrentNick);
|
||||
} else {
|
||||
this.api.resolveUser(event.server, event.user, function(user) {
|
||||
if(!user) {
|
||||
this.internalAPI.createUser(event.server,
|
||||
event.user, checkCurrentNick);
|
||||
if(event.user != user.currentNick) {
|
||||
user.currentNick = event.user;
|
||||
this.db.save('users', user.id, user, function() { done(user); });
|
||||
} else {
|
||||
checkCurrentNick(user);
|
||||
done(user);
|
||||
}
|
||||
}.bind(this));
|
||||
}
|
||||
}
|
||||
});
|
||||
}.bind(this);
|
||||
var checkChannelUsers = function(done) {
|
||||
var needsUpdating = false;
|
||||
@ -201,7 +190,6 @@ var users = function(dbot) {
|
||||
checkUser(function(user) {
|
||||
event.rUser = user;
|
||||
|
||||
if(!_.has(this.userCache, event.server)) this.userCache[event.server] = {};
|
||||
if(!_.has(this.userCache[event.server], event.rUser.currentNick)) {
|
||||
this.userCache[event.server][event.rUser.currentNick] = event.rUser.id;
|
||||
} else if(this.userCache[event.server][event.rUser.currentNick] != event.rUser.id) {
|
||||
|
Loading…
Reference in New Issue
Block a user