mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-16 03:23:29 +01:00
refactor(Options): separate default settings for make cache (#6330)
This commit is contained in:
@@ -102,21 +102,7 @@ class Options extends null {
|
|||||||
static createDefault() {
|
static createDefault() {
|
||||||
return {
|
return {
|
||||||
shardCount: 1,
|
shardCount: 1,
|
||||||
makeCache: this.cacheWithLimits({
|
makeCache: this.cacheWithLimits(this.defaultMakeCacheSettings),
|
||||||
MessageManager: 200,
|
|
||||||
ChannelManager: {
|
|
||||||
sweepInterval: 3600,
|
|
||||||
sweepFilter: require('./Util').archivedThreadSweepFilter(),
|
|
||||||
},
|
|
||||||
GuildChannelManager: {
|
|
||||||
sweepInterval: 3600,
|
|
||||||
sweepFilter: require('./Util').archivedThreadSweepFilter(),
|
|
||||||
},
|
|
||||||
ThreadManager: {
|
|
||||||
sweepInterval: 3600,
|
|
||||||
sweepFilter: require('./Util').archivedThreadSweepFilter(),
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
messageCacheLifetime: 0,
|
messageCacheLifetime: 0,
|
||||||
messageSweepInterval: 0,
|
messageSweepInterval: 0,
|
||||||
invalidRequestWarningInterval: 0,
|
invalidRequestWarningInterval: 0,
|
||||||
@@ -173,6 +159,9 @@ class Options extends null {
|
|||||||
* @example
|
* @example
|
||||||
* // Sweep messages every 5 minutes, removing messages that have not been edited or created in the last 30 minutes
|
* // Sweep messages every 5 minutes, removing messages that have not been edited or created in the last 30 minutes
|
||||||
* Options.cacheWithLimits({
|
* Options.cacheWithLimits({
|
||||||
|
* // Keep default thread sweeping behavior
|
||||||
|
* ...Options.defaultMakeCacheSettings,
|
||||||
|
* // Override MessageManager
|
||||||
* MessageManager: {
|
* MessageManager: {
|
||||||
* sweepInterval: 300,
|
* sweepInterval: 300,
|
||||||
* sweepFilter: LimitedCollection.filterByLifetime({
|
* sweepFilter: LimitedCollection.filterByLifetime({
|
||||||
@@ -221,6 +210,35 @@ class Options extends null {
|
|||||||
const { Collection } = require('@discordjs/collection');
|
const { Collection } = require('@discordjs/collection');
|
||||||
return () => new Collection();
|
return () => new Collection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The default settings passed to {@link Options.cacheWithLimits}.
|
||||||
|
* The caches that this changes are:
|
||||||
|
* * `MessageManager` - Limit to 200 messages
|
||||||
|
* * `ChannelManager` - Sweep archived threads
|
||||||
|
* * `GuildChannelManager` - Sweep archived threads
|
||||||
|
* * `ThreadManager` - Sweep archived threads
|
||||||
|
* <info>If you want to keep default behavior and add on top of it you can use this object and add on to it, e.g.
|
||||||
|
* `makeCache: Options.cacheWithLimits({ ...Options.defaultmakeCacheSettings, ReactionManager: 0 })`</info>
|
||||||
|
* @type {Object<string, LimitedCollectionOptions|number>}
|
||||||
|
*/
|
||||||
|
static get defaultMakeCacheSettings() {
|
||||||
|
return {
|
||||||
|
MessageManager: 200,
|
||||||
|
ChannelManager: {
|
||||||
|
sweepInterval: 3600,
|
||||||
|
sweepFilter: require('./Util').archivedThreadSweepFilter(),
|
||||||
|
},
|
||||||
|
GuildChannelManager: {
|
||||||
|
sweepInterval: 3600,
|
||||||
|
sweepFilter: require('./Util').archivedThreadSweepFilter(),
|
||||||
|
},
|
||||||
|
ThreadManager: {
|
||||||
|
sweepInterval: 3600,
|
||||||
|
sweepFilter: require('./Util').archivedThreadSweepFilter(),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Options;
|
module.exports = Options;
|
||||||
|
|||||||
1
typings/index.d.ts
vendored
1
typings/index.d.ts
vendored
@@ -449,6 +449,7 @@ export class ClientUser extends User {
|
|||||||
|
|
||||||
export class Options extends null {
|
export class Options extends null {
|
||||||
private constructor();
|
private constructor();
|
||||||
|
public static defaultMakeCacheSettings: CacheWithLimitsOptions;
|
||||||
public static createDefaultOptions(): ClientOptions;
|
public static createDefaultOptions(): ClientOptions;
|
||||||
public static cacheWithLimits(settings?: CacheWithLimitsOptions): CacheFactory;
|
public static cacheWithLimits(settings?: CacheWithLimitsOptions): CacheFactory;
|
||||||
public static cacheEverything(): CacheFactory;
|
public static cacheEverything(): CacheFactory;
|
||||||
|
|||||||
Reference in New Issue
Block a user