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 down gc aggresiveness
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 17302b1 commit 13fedea
Showing 1 changed file with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { Listener } from "../../../Stores/Listener.js";
import { clientId, stateChannels, stateRoles } from "../../../config.js";

export class GuildCreateListener extends Listener {
public count = 0;
public gcEvery = 256;
public constructor(context: ListenerContext) {
super(context, {
event: GatewayDispatchEvents.GuildCreate
Expand Down Expand Up @@ -306,12 +308,7 @@ 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`);
this.logger.debug(`Flushing ${ops.length} operations for ${payload.data.d.id} to the database`);

for (const op of ops) {
try {
Expand All @@ -331,17 +328,19 @@ 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(
RabbitMQ.GATEWAY_QUEUE_SEND,
RoutingKey(clientId, payload.shardId),
Buffer.from(JSON.stringify(payload.data))
);

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`);
global.gc();
}
}
}

0 comments on commit 13fedea

Please sign in to comment.