From ea4344ad987e43734544a2a698855e2752306e87 Mon Sep 17 00:00:00 2001 From: didinele Date: Mon, 8 Mar 2021 09:27:08 +0200 Subject: [PATCH] fix(gateway/gateway-service): remove built-in caching --- libs/gateway/package.json | 2 -- libs/gateway/src/websocket/Cluster.ts | 9 -------- .../src/websocket/WebsocketConnection.ts | 9 +------- pnpm-lock.yaml | 22 ++++++++++--------- services/gateway/Dockerfile | 4 ---- services/gateway/package.json | 3 --- services/gateway/src/index.ts | 7 ------ 7 files changed, 13 insertions(+), 43 deletions(-) diff --git a/libs/gateway/package.json b/libs/gateway/package.json index 761901a..a8a20b0 100644 --- a/libs/gateway/package.json +++ b/libs/gateway/package.json @@ -43,9 +43,7 @@ "@cordis/common": "workspace:^0.1.7", "@cordis/error": "workspace:^0.1.7", "@cordis/queue": "workspace:^0.1.7", - "@cordis/redis-store": "workspace:^0.1.7", "@cordis/rest": "workspace:^0.1.7", - "@cordis/store": "workspace:^0.1.7", "common-tags": "^1.8.0", "discord-api-types": "^0.12.1", "tslib": "^2.1.0", diff --git a/libs/gateway/src/websocket/Cluster.ts b/libs/gateway/src/websocket/Cluster.ts index ac9795a..6ccf2d8 100644 --- a/libs/gateway/src/websocket/Cluster.ts +++ b/libs/gateway/src/websocket/Cluster.ts @@ -7,10 +7,7 @@ import { } from './WebsocketConnection'; import { stripIndent } from 'common-tags'; import { RestManager, MemoryMutex, RedisMutex } from '@cordis/rest'; -import { Store, IStore } from '@cordis/store'; -import { RedisStore } from '@cordis/redis-store'; import { - APIGuild, APIUser, GatewayDispatchPayload, GatewaySendPayload, @@ -117,11 +114,6 @@ export class Cluster extends EventEmitter { */ public readonly shards: WebsocketConnection[] = []; - /** - * Guild storage - */ - public readonly guilds: IStore; - /** * REST instance */ @@ -193,7 +185,6 @@ export class Cluster extends EventEmitter { ...shardOptions } = options; - this.guilds = redis ? new RedisStore({ redis, hash: 'guilds', encode: JSON.stringify, decode: JSON.parse }) : new Store(); this.rest = new RestManager(auth, { mutex: redis ? new RedisMutex(redis) : new MemoryMutex() }); this.shardCount = shardCount; this.startingShard = startingShard; diff --git a/libs/gateway/src/websocket/WebsocketConnection.ts b/libs/gateway/src/websocket/WebsocketConnection.ts index 8e2fcf8..c491b62 100644 --- a/libs/gateway/src/websocket/WebsocketConnection.ts +++ b/libs/gateway/src/websocket/WebsocketConnection.ts @@ -720,7 +720,7 @@ export class WebsocketConnection { } }; - private async _handleDispatch(payload: GatewayDispatchPayload): Promise { + private _handleDispatch(payload: GatewayDispatchPayload) { if (this._sequence == null || payload.s > this._sequence) this._sequence = payload.s; switch (payload.t) { @@ -758,18 +758,11 @@ export class WebsocketConnection { } this._refreshTimeout('guilds'); - } else { - await this.cluster.guilds.set(payload.d.id, payload.d); } break; } - case GatewayDispatchEvents.GuildDelete: { - if (!payload.d.unavailable) await this.cluster.guilds.delete(payload.d.id); - break; - } - case GatewayDispatchEvents.Resumed: { this._clearTimeout('reconnecting'); this.debug(`Resumed Session ${this._sessionId}; Replayed ${payload.s - this._sequence} events`); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 55594e6..370b9f9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -112,9 +112,7 @@ importers: '@cordis/common': link:../common '@cordis/error': link:../error '@cordis/queue': link:../queue - '@cordis/redis-store': link:../redis-store '@cordis/rest': link:../rest - '@cordis/store': link:../store common-tags: 1.8.0 discord-api-types: 0.12.1 tslib: 2.1.0 @@ -132,9 +130,7 @@ importers: '@cordis/common': workspace:^0.1.7 '@cordis/error': workspace:^0.1.7 '@cordis/queue': workspace:^0.1.7 - '@cordis/redis-store': workspace:^0.1.7 '@cordis/rest': workspace:^0.1.7 - '@cordis/store': workspace:^0.1.7 '@types/common-tags': ^1.8.0 '@types/ioredis': ^4.19.4 '@types/node': ^14.14.31 @@ -237,10 +233,7 @@ importers: '@cordis/brokers': link:../../libs/brokers '@cordis/common': link:../../libs/common '@cordis/gateway': link:../../libs/gateway - '@cordis/redis-store': link:../../libs/redis-store - '@cordis/store': link:../../libs/store erlpack: github.com/discord/erlpack/e27db8f82892bdb9b28a0547cc394d68b5d2242d - ioredis: 4.22.0 tslib: 2.1.0 yargs: 15.4.1 zlib-sync: 0.1.7 @@ -253,13 +246,10 @@ importers: '@cordis/brokers': workspace:^0.1.7 '@cordis/common': workspace:^0.1.7 '@cordis/gateway': workspace:^0.1.7 - '@cordis/redis-store': workspace:^0.1.7 - '@cordis/store': workspace:^0.1.7 '@types/node': ^14.14.31 '@types/yargs': ^15.0.13 discord-api-types: ^0.12.1 erlpack: github:discord/erlpack - ioredis: ^4.22.0 tslib: ^2.1.0 typescript: ^4.2.2 yargs: ^15.4.1 @@ -2297,6 +2287,7 @@ packages: resolution: integrity: sha512-t6wbgtoCXvAzst7QgXxJYqPt0usEfbgQdftEPbLL/cvv6HPE5VgvqCuAIDR0NgU52ds6rFwqrgakNLrHEjCbrQ== /cluster-key-slot/1.1.0: + dev: true engines: node: '>=0.10.0' resolution: @@ -2474,6 +2465,7 @@ packages: /debug/4.3.1: dependencies: ms: 2.1.2 + dev: true engines: node: '>=6.0' peerDependencies: @@ -2551,6 +2543,7 @@ packages: resolution: integrity: sha1-3zrhmayt+31ECqrgsp4icrJOxhk= /denque/1.5.0: + dev: true engines: node: '>=0.10' resolution: @@ -3454,6 +3447,7 @@ packages: redis-errors: 1.2.0 redis-parser: 3.0.0 standard-as-callback: 2.0.1 + dev: true engines: node: '>=6' resolution: @@ -4381,9 +4375,11 @@ packages: resolution: integrity: sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw== /lodash.defaults/4.2.0: + dev: true resolution: integrity: sha1-0JF4cW/+pN3p5ft7N/bwgCJ0WAw= /lodash.flatten/4.4.0: + dev: true resolution: integrity: sha1-8xwiIlqWMtK7+OSt2+8kCqdlph8= /lodash.sortby/4.7.0: @@ -4540,6 +4536,7 @@ packages: resolution: integrity: sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g= /ms/2.1.2: + dev: true resolution: integrity: sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w== /nan/2.14.2: @@ -4785,6 +4782,7 @@ packages: resolution: integrity: sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw== /p-map/2.1.0: + dev: true engines: node: '>=6' resolution: @@ -5022,9 +5020,11 @@ packages: resolution: integrity: sha1-hSBLVNuoLVdC4oyWdW70OvUOM4Q= /redis-commands/1.7.0: + dev: true resolution: integrity: sha512-nJWqw3bTFy21hX/CPKHth6sfhZbdiHP6bTawSgQBlKOVRG7EZkfHbbHwQJnrE4vsQf0CMNE+3gJ4Fmm16vdVlQ== /redis-errors/1.2.0: + dev: true engines: node: '>=4' resolution: @@ -5032,6 +5032,7 @@ packages: /redis-parser/3.0.0: dependencies: redis-errors: 1.2.0 + dev: true engines: node: '>=4' resolution: @@ -5565,6 +5566,7 @@ packages: resolution: integrity: sha512-gL//fkxfWUsIlFL2Tl42Cl6+HFALEaB1FU76I/Fy+oZjRreP7OPMXFlGbxM7NQsI0ZpUfw76sHnv0WNYuTb7Iw== /standard-as-callback/2.0.1: + dev: true resolution: integrity: sha512-NQOxSeB8gOI5WjSaxjBgog2QFw55FV8TkS6Y07BiB3VJ8xNTvUYm0wl0s8ObgQ5NhdpnNfigMIKjgPESzgr4tg== /static-extend/0.1.2: diff --git a/services/gateway/Dockerfile b/services/gateway/Dockerfile index 4b88d9d..0f7f415 100644 --- a/services/gateway/Dockerfile +++ b/services/gateway/Dockerfile @@ -17,9 +17,7 @@ COPY libs/common/package.json ./libs/common/ COPY libs/error/package.json ./libs/error/ COPY libs/gateway/package.json ./libs/gateway/ COPY libs/queue/package.json ./libs/queue/ -COPY libs/redis-store/package.json ./libs/redis-store/ COPY libs/rest/package.json ./libs/rest/ -COPY libs/store/package.json ./libs/store/ COPY services/gateway/package.json ./services/gateway/package.json RUN pnpm i --frozen-lockfile && apk del .build-deps @@ -30,9 +28,7 @@ COPY libs/common ./libs/common COPY libs/error ./libs/error COPY libs/gateway ./libs/gateway COPY libs/queue ./libs/queue -COPY libs/redis-store ./libs/redis-store COPY libs/rest ./libs/rest -COPY libs/store ./libs/store COPY services/gateway ./services/gateway RUN pnpm run build && pnpm prune --prod diff --git a/services/gateway/package.json b/services/gateway/package.json index bd6cc2d..96a09ab 100644 --- a/services/gateway/package.json +++ b/services/gateway/package.json @@ -31,10 +31,7 @@ "@cordis/brokers": "workspace:^0.1.7", "@cordis/common": "workspace:^0.1.7", "@cordis/gateway": "workspace:^0.1.7", - "@cordis/redis-store": "workspace:^0.1.7", - "@cordis/store": "workspace:^0.1.7", "erlpack": "github:discord/erlpack", - "ioredis": "^4.22.0", "tslib": "^2.1.0", "yargs": "^15.4.1", "zlib-sync": "^0.1.7" diff --git a/services/gateway/src/index.ts b/services/gateway/src/index.ts index ac9ea43..19f34a4 100644 --- a/services/gateway/src/index.ts +++ b/services/gateway/src/index.ts @@ -1,6 +1,5 @@ import * as yargs from 'yargs'; import { createAmqp, RoutingServer, PubSubClient } from '@cordis/brokers'; -import createRedis, { Redis } from 'ioredis'; import { Cluster, IntentKeys } from '@cordis/gateway'; import type { DiscordEvents } from '@cordis/common'; import type { GatewaySendPayload } from 'discord-api-types/v8'; @@ -124,11 +123,6 @@ const main = async () => { process.exit(1); }); - let redis: Redis | null = null; - if (argv['redis-url']) { - redis = new createRedis(argv['redis-url']); - } - const service = new RoutingServer(channel); const cluster = new Cluster( argv.auth, @@ -142,7 +136,6 @@ const main = async () => { reconnectTimeout: argv['ws-reconnect-timeout'], largeThreshold: argv['ws-large-threshold'], intents: argv['ws-intents'] as IntentKeys[], - redis: redis ?? undefined, shardCount: argv['shard-count'], startingShard: argv['starting-shard'], totalShardCount: argv['total-shard-count']