Skip to content

Commit

Permalink
fix caching issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Starman3787 committed Mar 11, 2024
1 parent a3f66d3 commit 8d11b89
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gluon",
"version": "1.17.18",
"version": "1.17.19",
"description": "Discord API library for Quark",
"main": "./index.js",
"scripts": {
Expand All @@ -27,8 +27,7 @@
"node-fetch": "^2.6.1",
"utf-8-validate": "^5.0.5",
"ws": "^7.4.6",
"zlib-sync": "^0.1.7",
"@jsdoc/salty": "^0.2.7"
"zlib-sync": "^0.1.7"
},
"devDependencies": {
"clean-jsdoc-theme": "^3.2.7",
Expand Down
10 changes: 6 additions & 4 deletions src/managers/ChannelMessageManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,14 @@ class ChannelMessageManager {
const currentCacheKeys = this.cache.keys();
const currentCacheValues = this.cache.values();

for (let i = 0, cacheSize = currentCacheSize; i < currentCacheSize; i++)
if (currentCacheValues[i])
if (currentCacheValues[i].timestamp + (DEFAULT_MESSAGE_EXPIRY_SECONDS * (this.client.increasedCache.get(this.channel.guild_id?.toString() || this.channel.guild.id.toString())) ? this.client.increaseCacheBy : 1) < currentTime || (cacheCount != 0 ? cacheSize > cacheCount : false)) {
this.cache.delete(currentCacheKeys[i]);
for (let i = 0, cacheSize = currentCacheSize; i < currentCacheSize; i++) {
const currentCacheValue = currentCacheValues.next().value;
if (currentCacheValue)
if (currentCacheValue.timestamp + (DEFAULT_MESSAGE_EXPIRY_SECONDS * (this.client.increasedCache.get(this.channel.guild_id?.toString() || this.channel.guild.id.toString())) ? this.client.increaseCacheBy : 1) < currentTime || (cacheCount != 0 ? cacheSize > cacheCount : false)) {
this.cache.delete(currentCacheKeys.next().value);
cacheSize--;
}
}

return this.cache.size;

Expand Down
4 changes: 2 additions & 2 deletions src/managers/GuildMemberManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ class GuildMemberManager {
const currentCacheSize = this.cache.size;
const currentCacheKeys = this.cache.keys();

for (let i = 0, cacheSize = currentCacheSize; cacheCount < cacheSize; i++, cacheSize--)
this.cache.delete(currentCacheKeys[i]);
for (let cacheSize = currentCacheSize; cacheCount < cacheSize; cacheSize--)
this.cache.delete(currentCacheKeys.next().value);

return this.cache.size;

Expand Down

0 comments on commit 8d11b89

Please sign in to comment.