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

Commit

Permalink
fix(GuildCreateListener):turn up gc aggressiveness
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 13fedea commit 68e4224
Showing 1 changed file with 2 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { clientId, stateChannels, stateRoles } from "../../../config.js";

export class GuildCreateListener extends Listener {
public count = 0;
public gcEvery = 256;
public gcEvery = 50;
public constructor(context: ListenerContext) {
super(context, {
event: GatewayDispatchEvents.GuildCreate
Expand Down Expand Up @@ -40,8 +40,6 @@ export class GuildCreateListener extends Listener {

let ops: SQL[] = [];

this.logger.debug(`Received GUILD_CREATE event for guild ${payload.data.d.id}`);

ops.push(
this.store.drizzle
.insert(guilds)
Expand Down Expand Up @@ -308,8 +306,6 @@ export class GuildCreateListener extends Listener {
// @ts-expect-error deallocate array
payload.data.d.voice_states = null;

this.logger.debug(`Flushing ${ops.length} operations for ${payload.data.d.id} to the database`);

for (const op of ops) {
try {
await this.store.drizzle.execute(op);
Expand All @@ -328,8 +324,6 @@ export class GuildCreateListener extends Listener {
// @ts-expect-error deallocate array
ops = null;

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

await this.store.amqp.publish(
RabbitMQ.GATEWAY_QUEUE_SEND,
RoutingKey(clientId, payload.shardId),
Expand All @@ -339,7 +333,7 @@ export class GuildCreateListener extends Listener {
this.count++;

if (global.gc && this.count % this.gcEvery === 0) {
this.logger.debug(`Running garbage collection, ${this.count} Guilds flushed to the database so far`);
this.logger.info(`Running garbage collection, ${this.count} Guilds flushed to the database so far`);
global.gc();
}
}
Expand Down

0 comments on commit 68e4224

Please sign in to comment.