Log gateway handling time
This commit is contained in:
parent
1ee84431e4
commit
02efa17a04
@ -7,6 +7,7 @@ export async function onGuildSubscriptionsBulk(
|
|||||||
this: WebSocket,
|
this: WebSocket,
|
||||||
payload: Payload,
|
payload: Payload,
|
||||||
) {
|
) {
|
||||||
|
const startTime = Date.now();
|
||||||
check.call(this, GuildSubscriptionsBulkSchema, payload.d);
|
check.call(this, GuildSubscriptionsBulkSchema, payload.d);
|
||||||
const body = payload.d as GuildSubscriptionsBulkSchema;
|
const body = payload.d as GuildSubscriptionsBulkSchema;
|
||||||
|
|
||||||
@ -21,4 +22,7 @@ export async function onGuildSubscriptionsBulk(
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
console.log(
|
||||||
|
`[Gateway] GuildSubscriptionsBulk processed ${Object.keys(body.subscriptions).length} subscriptions for user ${this.user_id} in ${Date.now() - startTime}ms`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -71,6 +71,7 @@ const tryGetUserFromToken = async (...args: Parameters<typeof checkToken>) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export async function onIdentify(this: WebSocket, data: Payload) {
|
export async function onIdentify(this: WebSocket, data: Payload) {
|
||||||
|
const startTime = Date.now();
|
||||||
if (this.user_id) {
|
if (this.user_id) {
|
||||||
// we've already identified
|
// we've already identified
|
||||||
return this.close(CLOSECODES.Already_authenticated);
|
return this.close(CLOSECODES.Already_authenticated);
|
||||||
@ -521,4 +522,8 @@ export async function onIdentify(this: WebSocket, data: Payload) {
|
|||||||
//TODO send VOICE_STATE_UPDATE to let the client know if another device is already connected to a voice channel
|
//TODO send VOICE_STATE_UPDATE to let the client know if another device is already connected to a voice channel
|
||||||
|
|
||||||
await setupListener.call(this);
|
await setupListener.call(this);
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`[Gateway] IDENTIFY ${this.user_id} in ${Date.now() - startTime}ms`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -212,6 +212,7 @@ async function subscribeToMemberEvents(this: WebSocket, user_id: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function onLazyRequest(this: WebSocket, { d }: Payload) {
|
export async function onLazyRequest(this: WebSocket, { d }: Payload) {
|
||||||
|
const startTime = Date.now();
|
||||||
// TODO: check data
|
// TODO: check data
|
||||||
check.call(this, LazyRequestSchema, d);
|
check.call(this, LazyRequestSchema, d);
|
||||||
const { guild_id, typing, channels, activities, members } =
|
const { guild_id, typing, channels, activities, members } =
|
||||||
@ -308,7 +309,7 @@ export async function onLazyRequest(this: WebSocket, { d }: Payload) {
|
|||||||
.flat()
|
.flat()
|
||||||
.unique();
|
.unique();
|
||||||
|
|
||||||
return await Send(this, {
|
await Send(this, {
|
||||||
op: OPCODES.Dispatch,
|
op: OPCODES.Dispatch,
|
||||||
s: this.sequence++,
|
s: this.sequence++,
|
||||||
t: "GUILD_MEMBER_LIST_UPDATE",
|
t: "GUILD_MEMBER_LIST_UPDATE",
|
||||||
@ -327,4 +328,8 @@ export async function onLazyRequest(this: WebSocket, { d }: Payload) {
|
|||||||
groups,
|
groups,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`[Gateway] LAZY_REQUEST ${guild_id} ${channel_id} took ${Date.now() - startTime}ms`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,6 +27,7 @@ import {
|
|||||||
import { check } from "./instanceOf";
|
import { check } from "./instanceOf";
|
||||||
|
|
||||||
export async function onPresenceUpdate(this: WebSocket, { d }: Payload) {
|
export async function onPresenceUpdate(this: WebSocket, { d }: Payload) {
|
||||||
|
const startTime = Date.now();
|
||||||
check.call(this, ActivitySchema, d);
|
check.call(this, ActivitySchema, d);
|
||||||
const presence = d as ActivitySchema;
|
const presence = d as ActivitySchema;
|
||||||
|
|
||||||
@ -50,4 +51,8 @@ export async function onPresenceUpdate(this: WebSocket, { d }: Payload) {
|
|||||||
client_status: session.client_status,
|
client_status: session.client_status,
|
||||||
},
|
},
|
||||||
} as PresenceUpdateEvent);
|
} as PresenceUpdateEvent);
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`Presence update for user ${this.user_id} processed in ${Date.now() - startTime}ms`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,6 +30,7 @@ import { check } from "./instanceOf";
|
|||||||
import { FindManyOptions, ILike, In } from "typeorm";
|
import { FindManyOptions, ILike, In } from "typeorm";
|
||||||
|
|
||||||
export async function onRequestGuildMembers(this: WebSocket, { d }: Payload) {
|
export async function onRequestGuildMembers(this: WebSocket, { d }: Payload) {
|
||||||
|
const startTime = Date.now();
|
||||||
// Schema validation can only accept either string or array, so transforming it here to support both
|
// Schema validation can only accept either string or array, so transforming it here to support both
|
||||||
if (!d.guild_id) throw new Error('"guild_id" is required');
|
if (!d.guild_id) throw new Error('"guild_id" is required');
|
||||||
d.guild_id = Array.isArray(d.guild_id) ? d.guild_id[0] : d.guild_id;
|
d.guild_id = Array.isArray(d.guild_id) ? d.guild_id[0] : d.guild_id;
|
||||||
@ -52,12 +53,12 @@ export async function onRequestGuildMembers(this: WebSocket, { d }: Payload) {
|
|||||||
user_ids = user_ids as string[] | undefined;
|
user_ids = user_ids as string[] | undefined;
|
||||||
|
|
||||||
if (d.query && (!limit || Number.isNaN(limit))) {
|
if (d.query && (!limit || Number.isNaN(limit))) {
|
||||||
console.log("Query:", d)
|
console.log("Query:", d);
|
||||||
throw new Error('"query" requires "limit" to be set');
|
throw new Error('"query" requires "limit" to be set');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (d.query && user_ids) {
|
if (d.query && user_ids) {
|
||||||
console.log("Query:", d)
|
console.log("Query:", d);
|
||||||
throw new Error('"query" and "user_ids" are mutually exclusive');
|
throw new Error('"query" and "user_ids" are mutually exclusive');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,4 +201,8 @@ export async function onRequestGuildMembers(this: WebSocket, { d }: Payload) {
|
|||||||
d: chunk,
|
d: chunk,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`[Gateway] REQUEST_GUILD_MEMBERS took ${Date.now() - startTime}ms for guild ${guild_id} with ${members.length} members`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,6 +22,7 @@ import {
|
|||||||
import { check } from "./instanceOf";
|
import { check } from "./instanceOf";
|
||||||
|
|
||||||
export async function onStreamCreate(this: WebSocket, data: Payload) {
|
export async function onStreamCreate(this: WebSocket, data: Payload) {
|
||||||
|
const startTime = Date.now();
|
||||||
check.call(this, StreamCreateSchema, data.d);
|
check.call(this, StreamCreateSchema, data.d);
|
||||||
const body = data.d as StreamCreateSchema;
|
const body = data.d as StreamCreateSchema;
|
||||||
|
|
||||||
@ -124,6 +125,10 @@ export async function onStreamCreate(this: WebSocket, data: Payload) {
|
|||||||
guild_id: voiceState.guild_id,
|
guild_id: voiceState.guild_id,
|
||||||
channel_id: voiceState.channel_id,
|
channel_id: voiceState.channel_id,
|
||||||
} as VoiceStateUpdateEvent);
|
} as VoiceStateUpdateEvent);
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`[Gateway] STREAM_CREATE for user ${this.user_id} in channel ${body.channel_id} with stream key ${streamKey} in ${Date.now() - startTime}ms`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
//stream key:
|
//stream key:
|
||||||
|
|||||||
@ -10,6 +10,7 @@ import {
|
|||||||
import { check } from "./instanceOf";
|
import { check } from "./instanceOf";
|
||||||
|
|
||||||
export async function onStreamDelete(this: WebSocket, data: Payload) {
|
export async function onStreamDelete(this: WebSocket, data: Payload) {
|
||||||
|
const startTime = Date.now();
|
||||||
check.call(this, StreamDeleteSchema, data.d);
|
check.call(this, StreamDeleteSchema, data.d);
|
||||||
const body = data.d as StreamDeleteSchema;
|
const body = data.d as StreamDeleteSchema;
|
||||||
|
|
||||||
@ -73,4 +74,8 @@ export async function onStreamDelete(this: WebSocket, data: Payload) {
|
|||||||
guild_id: guildId,
|
guild_id: guildId,
|
||||||
channel_id: channelId,
|
channel_id: channelId,
|
||||||
} as StreamDeleteEvent);
|
} as StreamDeleteEvent);
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`[Gateway] STREAM_DELETE for user ${this.user_id} in channel ${channelId} with stream key ${body.stream_key} in ${Date.now() - startTime}ms`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,6 +17,7 @@ import { check } from "./instanceOf";
|
|||||||
import { Not } from "typeorm";
|
import { Not } from "typeorm";
|
||||||
|
|
||||||
export async function onStreamWatch(this: WebSocket, data: Payload) {
|
export async function onStreamWatch(this: WebSocket, data: Payload) {
|
||||||
|
const startTime = Date.now();
|
||||||
check.call(this, StreamWatchSchema, data.d);
|
check.call(this, StreamWatchSchema, data.d);
|
||||||
const body = data.d as StreamWatchSchema;
|
const body = data.d as StreamWatchSchema;
|
||||||
|
|
||||||
@ -95,4 +96,8 @@ export async function onStreamWatch(this: WebSocket, data: Payload) {
|
|||||||
},
|
},
|
||||||
user_id: this.user_id,
|
user_id: this.user_id,
|
||||||
} as StreamServerUpdateEvent);
|
} as StreamServerUpdateEvent);
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`[Gateway] STREAM_WATCH for user ${this.user_id} in channel ${channelId} with stream key ${body.stream_key} in ${Date.now() - startTime}ms`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -37,6 +37,7 @@ import { check } from "./instanceOf";
|
|||||||
// Having MANAGE_CHANNELS permission bypasses this limit and allows you to join regardless of the channel being full or not.
|
// Having MANAGE_CHANNELS permission bypasses this limit and allows you to join regardless of the channel being full or not.
|
||||||
|
|
||||||
export async function onVoiceStateUpdate(this: WebSocket, data: Payload) {
|
export async function onVoiceStateUpdate(this: WebSocket, data: Payload) {
|
||||||
|
const startTime = Date.now();
|
||||||
check.call(this, VoiceStateUpdateSchema, data.d);
|
check.call(this, VoiceStateUpdateSchema, data.d);
|
||||||
const body = data.d as VoiceStateUpdateSchema;
|
const body = data.d as VoiceStateUpdateSchema;
|
||||||
const isNew = body.channel_id === null && body.guild_id === null;
|
const isNew = body.channel_id === null && body.guild_id === null;
|
||||||
@ -167,4 +168,8 @@ export async function onVoiceStateUpdate(this: WebSocket, data: Payload) {
|
|||||||
user_id: voiceState.user_id,
|
user_id: voiceState.user_id,
|
||||||
} as VoiceServerUpdateEvent);
|
} as VoiceServerUpdateEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`[Gateway] VOICE_STATE_UPDATE for user ${this.user_id} in channel ${voiceState.channel_id} in guild ${voiceState.guild_id} in ${Date.now() - startTime}ms`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user