From 8c2e6b70b84ff597d15aa99712db5d719fd5a0af Mon Sep 17 00:00:00 2001 From: "Matt (IPv4) Cowley" Date: Wed, 30 Dec 2020 10:21:34 +0000 Subject: [PATCH] refactor(Message): remove stored edit history (#5155) --- src/client/Client.js | 7 ------- src/structures/Message.js | 24 ------------------------ src/util/Constants.js | 3 --- typings/index.d.ts | 5 ----- 4 files changed, 39 deletions(-) diff --git a/src/client/Client.js b/src/client/Client.js index dc8e1738e..79a1f44cc 100644 --- a/src/client/Client.js +++ b/src/client/Client.js @@ -459,13 +459,6 @@ class Client extends BaseClient { if (typeof options.messageSweepInterval !== 'number' || isNaN(options.messageSweepInterval)) { throw new TypeError('CLIENT_INVALID_OPTION', 'messageSweepInterval', 'a number'); } - if ( - typeof options.messageEditHistoryMaxSize !== 'number' || - isNaN(options.messageEditHistoryMaxSize) || - options.messageEditHistoryMaxSize < -1 - ) { - throw new TypeError('CLIENT_INVALID_OPTION', 'messageEditHistoryMaxSize', 'a number greater than or equal to -1'); - } if (typeof options.fetchAllMembers !== 'boolean') { throw new TypeError('CLIENT_INVALID_OPTION', 'fetchAllMembers', 'a boolean'); } diff --git a/src/structures/Message.js b/src/structures/Message.js index 13417d970..d07e2285c 100644 --- a/src/structures/Message.js +++ b/src/structures/Message.js @@ -185,13 +185,6 @@ class Message extends Base { } : null; - /** - * The previous versions of the message, sorted with the most recent first - * @type {Message[]} - * @private - */ - this._edits = []; - if (this.member && data.member) { this.member._patch(data.member); } else if (data.member && this.guild && this.author) { @@ -246,11 +239,6 @@ class Message extends Base { */ patch(data) { const clone = this._clone(); - const { messageEditHistoryMaxSize } = this.client.options; - if (messageEditHistoryMaxSize !== 0) { - const editsLimit = messageEditHistoryMaxSize === -1 ? Infinity : messageEditHistoryMaxSize; - if (this._edits.unshift(clone) > editsLimit) this._edits.pop(); - } if ('edited_timestamp' in data) this.editedTimestamp = new Date(data.edited_timestamp).getTime(); if ('content' in data) this.content = data.content; @@ -383,18 +371,6 @@ class Message extends Base { }); } - /** - * An array of cached versions of the message, including the current version - * Sorted from latest (first) to oldest (last) - * @type {Message[]} - * @readonly - */ - get edits() { - const copy = this._edits.slice(); - copy.unshift(this); - return copy; - } - /** * Whether the message is editable by the client user * @type {boolean} diff --git a/src/util/Constants.js b/src/util/Constants.js index 3af6122ac..298bbc196 100644 --- a/src/util/Constants.js +++ b/src/util/Constants.js @@ -18,8 +18,6 @@ const { Error, RangeError } = require('../errors'); * sweepable (in seconds, 0 for forever) * @property {number} [messageSweepInterval=0] How frequently to remove messages from the cache that are older than * the message cache lifetime (in seconds, 0 for never) - * @property {number} [messageEditHistoryMaxSize=-1] Maximum number of previous versions to hold for an edited message - * (-1 or Infinity for unlimited - don't do this without sweeping, otherwise memory usage may climb indefinitely.) * @property {boolean} [fetchAllMembers=false] Whether to cache all guild members and users upon startup, as well as * upon joining a guild (should be avoided whenever possible) * @property {MessageMentionOptions} [allowedMentions] Default value for {@link MessageOptions#allowedMentions} @@ -43,7 +41,6 @@ exports.DefaultOptions = { messageCacheMaxSize: 200, messageCacheLifetime: 0, messageSweepInterval: 0, - messageEditHistoryMaxSize: -1, fetchAllMembers: false, partials: [], restWsBridgeTimeout: 5000, diff --git a/typings/index.d.ts b/typings/index.d.ts index 35643d584..c4b14d8bb 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -951,7 +951,6 @@ declare module 'discord.js' { export class Message extends Base { constructor(client: Client, data: object, channel: TextChannel | DMChannel | NewsChannel); - private _edits: Message[]; private patch(data: object): Message; public activity: MessageActivity | null; @@ -968,7 +967,6 @@ declare module 'discord.js' { public readonly editable: boolean; public readonly editedAt: Date | null; public editedTimestamp: number | null; - public readonly edits: Message[]; public embeds: MessageEmbed[]; public readonly guild: Guild | null; public id: Snowflake; @@ -2332,7 +2330,6 @@ declare module 'discord.js' { messageCacheMaxSize?: number; messageCacheLifetime?: number; messageSweepInterval?: number; - messageEditHistoryMaxSize?: number; fetchAllMembers?: boolean; allowedMentions?: MessageMentionOptions; partials?: PartialTypes[]; @@ -3042,7 +3039,6 @@ declare module 'discord.js' { | 'pinnable' | 'url' | 'flags' - | 'edits' | 'embeds' > { attachments: Message['attachments']; @@ -3050,7 +3046,6 @@ declare module 'discord.js' { readonly deletable: boolean; readonly crosspostable: boolean; readonly editable: boolean; - readonly edits: Message['edits']; embeds: Message['embeds']; flags: Message['flags']; mentions: Message['mentions'];