Stop comparing for equality on update events and just emit for performance

This commit is contained in:
Amish Shah
2016-09-25 11:23:47 +01:00
parent c8636fd277
commit 0e8f1bef97
6 changed files with 21 additions and 7 deletions

File diff suppressed because one or more lines are too long

View File

@@ -10,7 +10,7 @@ class ChannelUpdateAction extends Action {
if (channel) {
const oldChannel = cloneObject(channel);
channel.setup(data);
if (!oldChannel.equals(data)) client.emit(Constants.Events.CHANNEL_UPDATE, oldChannel, channel);
client.emit(Constants.Events.CHANNEL_UPDATE, oldChannel, channel);
return {
old: oldChannel,
updated: channel,

View File

@@ -12,7 +12,7 @@ class GuildRoleUpdateAction extends Action {
let oldRole = null;
const role = guild.roles.get(roleData.id);
if (role && !role.equals(roleData)) {
if (role) {
oldRole = cloneObject(role);
role.setup(data.role);
client.emit(Constants.Events.GUILD_ROLE_UPDATE, guild, oldRole, role);

View File

@@ -10,7 +10,7 @@ class GuildUpdateAction extends Action {
if (guild) {
const oldGuild = cloneObject(guild);
guild.setup(data);
if (!oldGuild.equals(data)) client.emit(Constants.Events.GUILD_UPDATE, oldGuild, guild);
client.emit(Constants.Events.GUILD_UPDATE, oldGuild, guild);
return {
old: oldGuild,
updated: guild,

View File

@@ -9,7 +9,7 @@ class MessageUpdateAction extends Action {
const channel = client.channels.get(data.channel_id);
if (channel) {
const message = channel.messages.get(data.id);
if (message && !message.equals(data, true)) {
if (message) {
const oldMessage = cloneObject(message);
message.patch(data);
message._edits.unshift(oldMessage);

View File

@@ -22,8 +22,22 @@ client.on('guildMemberAdd', (g, m) => {
console.log(`${m.user.username} joined ${g.name}`);
})
client.on('guildMemberUpdate', (g, o, n) => {
console.log(o.nickname, n.nickname);
let c = 0;
client.on('channelUpdate', () => {
c++; console.log(c);
});
client.on('guildMemberUpdate', () => {
c++; console.log(c);
});
client.on('channelPinsUpdate', () => {
c++; console.log(c);
});
client.on('presenceUpdate', () => {
c++; console.log(c);
});
client.on('debug', console.log);