mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-11 00:53:31 +01:00
fix(Caching): sweep archived threads in all channel caches (#6312)
This commit is contained in:
@@ -15,7 +15,7 @@ const { TypeError } = require('../errors/DJSError.js');
|
||||
/**
|
||||
* Options for defining the behavior of a LimitedCollection
|
||||
* @typedef {Object} LimitedCollectionOptions
|
||||
* @property {?number} [maxSize=0] The maximum size of the Collection
|
||||
* @property {?number} [maxSize=Infinity] The maximum size of the Collection
|
||||
* @property {?Function} [keepOverLimit=null] A function, which is passed the value and key of an entry, ran to decide
|
||||
* to keep an entry past the maximum size
|
||||
* @property {?SweepFilter} [sweepFilter=null] A function ran every `sweepInterval` to determine how to sweep
|
||||
|
||||
@@ -104,12 +104,17 @@ class Options extends null {
|
||||
shardCount: 1,
|
||||
makeCache: this.cacheWithLimits({
|
||||
MessageManager: 200,
|
||||
ChannelManager: {
|
||||
sweepInterval: 3600,
|
||||
sweepFilter: require('./Util').archivedThreadSweepFilter(),
|
||||
},
|
||||
GuildChannelManager: {
|
||||
sweepInterval: 3600,
|
||||
sweepFilter: require('./Util').archivedThreadSweepFilter(),
|
||||
},
|
||||
ThreadManager: {
|
||||
sweepInterval: 3600,
|
||||
sweepFilter: require('./LimitedCollection').filterByLifetime({
|
||||
getComparisonTimestamp: e => e.archiveTimestamp,
|
||||
excludeFromSweep: e => !e.archived,
|
||||
}),
|
||||
sweepFilter: require('./Util').archivedThreadSweepFilter(),
|
||||
},
|
||||
}),
|
||||
messageCacheLifetime: 0,
|
||||
@@ -154,6 +159,7 @@ class Options extends null {
|
||||
* @returns {CacheFactory}
|
||||
* @example
|
||||
* // Store up to 200 messages per channel and discard archived threads if they were archived more than 4 hours ago.
|
||||
* // Note archived threads will remain in the guild and client caches with these settings
|
||||
* Options.cacheWithLimits({
|
||||
* MessageManager: 200,
|
||||
* ThreadManager: {
|
||||
|
||||
@@ -635,6 +635,21 @@ class Util extends null {
|
||||
setTimeout(resolve, ms);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a sweep filter that sweeps archived threads
|
||||
* @param {number} [lifetime=14400] How long a thread has to be archived to be valid for sweeping
|
||||
* @returns {SweepFilter}
|
||||
*/
|
||||
static archivedThreadSweepFilter(lifetime = 14400) {
|
||||
const filter = require('./LimitedCollection').filterByLifetime({
|
||||
lifetime,
|
||||
getComparisonTimestamp: e => e.archiveTimestamp,
|
||||
excludeFromSweep: e => !e.archived,
|
||||
});
|
||||
filter.isDefault = true;
|
||||
return filter;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Util;
|
||||
|
||||
Reference in New Issue
Block a user