Skip to content
This repository has been archived by the owner on Jul 15, 2024. It is now read-only.

Commit

Permalink
fix(GuildCreateListener): mess around with gc
Browse files Browse the repository at this point in the history
Co-authored-by: KagChi <[email protected]>
Co-authored-by: Vann <[email protected]>
  • Loading branch information
3 people authored Feb 21, 2024
1 parent b5882da commit a935dc1
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ export class GuildCreateListener extends Listener {
);

if (stateRoles) {
this.logger.debug(`Inserting ${payload.data.d.roles.length} roles for guild ${payload.data.d.id} into the database`);
const values = sql.empty();

for (const role of payload.data.d.roles) {
Expand All @@ -148,8 +147,6 @@ export class GuildCreateListener extends Listener {

const bot = payload.data.d.members.find(member => member.user?.id === clientId)!;

this.logger.debug(`Inserting bot ${bot.user!.id} into the database`);

ops.push(
this.store.drizzle
.insert(users)
Expand Down Expand Up @@ -228,7 +225,6 @@ export class GuildCreateListener extends Listener {
payload.data.d.members = null;

if (stateChannels && payload.data.d.channels.length > 0) {
this.logger.debug(`Inserting ${payload.data.d.channels.length} channels for guild ${payload.data.d.id} into the database`);
const values = sql.empty();
const values2 = sql.empty();

Expand Down Expand Up @@ -271,7 +267,6 @@ export class GuildCreateListener extends Listener {
const voiceState = payload.data.d.voice_states.find(voice => voice.user_id === clientId && voice.channel_id !== undefined);

if (voiceState) {
this.logger.debug(`Inserting voice state for bot ${bot.user!.id} in guild ${payload.data.d.id} into the database`);
ops.push(
this.store.drizzle
.insert(voiceStates)
Expand Down Expand Up @@ -311,6 +306,11 @@ export class GuildCreateListener extends Listener {
// @ts-expect-error deallocate array
payload.data.d.voice_states = null;

if (global.gc) {
this.logger.debug("Running first garbage collection");
global.gc();
}

this.logger.debug(`Flushing ${ops.length} operations to the database`);

for (const op of ops) {
Expand All @@ -331,6 +331,11 @@ export class GuildCreateListener extends Listener {
// @ts-expect-error deallocate array
ops = null;

if (global.gc) {
this.logger.debug("Running second garbage collection");
global.gc();
}

this.logger.debug(`Operations for ${payload.data.d.id} flushed to the database`);

await this.store.amqp.publish(
Expand Down

0 comments on commit a935dc1

Please sign in to comment.