fix(cache): actually disabling onPacket cache

This commit is contained in:
MARCROCK22 2024-08-26 01:58:49 +00:00
parent 6e029061d6
commit fc4c7ef3da
4 changed files with 15 additions and 14 deletions

7
src/cache/index.ts vendored
View File

@ -175,7 +175,10 @@ export class Cache {
this.bans = new Bans(this, client);
}
if (this.disabledCache.onPacket) delete this.onPacket;
if (this.disabledCache.onPacket) {
//@ts-expect-error
this.onPacket = () => {};
}
}
/** @internal */
@ -501,7 +504,7 @@ export class Cache {
await this.adapter.bulkSet(allData);
}
async onPacket?(event: GatewayDispatchPayload) {
async onPacket(event: GatewayDispatchPayload) {
switch (event.t) {
case 'READY':
await this.users?.set(event.d.user.id, event.d.user);

View File

@ -163,11 +163,11 @@ export class Client<Ready extends boolean = boolean> extends BaseClient {
this.__handleGuilds?.delete(packet.d.id);
if (!this.__handleGuilds?.size && [...this.gateway.values()].every(shard => shard.data.session_id)) {
delete this.__handleGuilds;
await this.cache.onPacket?.(packet);
await this.cache.onPacket(packet);
return this.events?.runEvent('BOT_READY', this, this.me, -1);
}
if (!this.__handleGuilds?.size) delete this.__handleGuilds;
return this.cache.onPacket?.(packet);
return this.cache.onPacket(packet);
}
await this.events?.execute(packet.t, packet, this as Client<true>, shardId);
break;

View File

@ -1,7 +1,6 @@
import { type GatewayDispatchPayload, type GatewaySendPayload, GatewayIntentBits } from '../types';
import { randomUUID } from 'node:crypto';
import { ApiHandler, Logger } from '..';
import type { Cache } from '../cache';
import { WorkerAdapter } from '../cache';
import { LogLevels, lazyLoadPackage, type DeepPartial, type When } from '../common';
import { EventHandler } from '../events';
@ -126,7 +125,7 @@ export class WorkerClient<Ready extends boolean = boolean> extends BaseClient {
if (this.__setServicesCache) {
this.setServices({
cache: {
disabledCache: this.options.disabledCache,
disabledCache: this.cache.disabledCache,
},
});
} else {
@ -137,7 +136,7 @@ export class WorkerClient<Ready extends boolean = boolean> extends BaseClient {
this.setServices({
cache: {
adapter,
disabledCache: this.options.disabledCache,
disabledCache: this.cache.disabledCache,
},
});
}
@ -242,7 +241,7 @@ export class WorkerClient<Ready extends boolean = boolean> extends BaseClient {
},
async handlePayload(shardId, payload) {
await handlePayload?.(shardId, payload);
await onPacket?.(payload, shardId);
await onPacket(payload, shardId);
if (sendPayloadToParent)
self.postMessage({
workerId: workerData.workerId,
@ -389,7 +388,7 @@ export class WorkerClient<Ready extends boolean = boolean> extends BaseClient {
this.__handleGuilds?.delete(packet.d.id);
if (!this.__handleGuilds?.size && [...this.shards.values()].every(shard => shard.data.session_id)) {
delete this.__handleGuilds;
await this.cache.onPacket?.(packet);
await this.cache.onPacket(packet);
this.postMessage({
type: 'WORKER_READY',
workerId: this.workerId,
@ -397,7 +396,7 @@ export class WorkerClient<Ready extends boolean = boolean> extends BaseClient {
return this.events?.runEvent('WORKER_READY', this, this.me, -1);
}
if (!this.__handleGuilds?.size) delete this.__handleGuilds;
return this.cache.onPacket?.(packet);
return this.cache.onPacket(packet);
}
await this.events?.execute(packet.t, packet, this, shardId);
break;
@ -465,7 +464,6 @@ export function generateShardInfo(shard: Shard): WorkerShardInfo {
}
interface WorkerClientOptions extends BaseClientOptions {
disabledCache?: Cache['disabledCache'];
commands?: NonNullable<Client['options']>['commands'];
handlePayload?: ShardManagerOptions['handlePayload'];
gateway?: ClientOptions['gateway'];

View File

@ -144,7 +144,7 @@ export class EventHandler extends BaseHandler {
const Event = this.values[name];
if (!Event) {
return runCache
? this.client.cache.onPacket?.({
? this.client.cache.onPacket({
t: name,
d: packet,
} as GatewayDispatchPayload)
@ -153,7 +153,7 @@ export class EventHandler extends BaseHandler {
try {
if (Event.data.once && Event.fired) {
return runCache
? this.client.cache.onPacket?.({
? this.client.cache.onPacket({
t: name,
d: packet,
} as GatewayDispatchPayload)
@ -162,7 +162,7 @@ export class EventHandler extends BaseHandler {
Event.fired = true;
const hook = await RawEvents[name]?.(client, packet as never);
if (runCache)
await this.client.cache.onPacket?.({
await this.client.cache.onPacket({
t: name,
d: packet,
} as GatewayDispatchPayload);