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 17302b1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
4 changes: 2 additions & 2 deletions services/kanao-gateway/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"build": "rimraf dist && swc ./src -d dist --config-file .swcrc --strip-leading-paths",
"lint": "eslint src",
"lint:fix": "eslint src --fix",
"start": "node -r dotenv/config dist/index.js",
"start:dev": "npm run build && node -r dotenv/config dist/index.js"
"start": "node --expose-gc -r dotenv/config dist/index.js",
"start:dev": "npm run build && node --expose-gc -r dotenv/config dist/index.js"
},
"dependencies": {
"@discordjs/collection": "^2.0.0",
Expand Down
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 17302b1

Please sign in to comment.