Skip to content

Commit

Permalink
[Fix] Clamp cache size (#3038)
Browse files Browse the repository at this point in the history
* fix

* clamp max cache size

* net 4.6.1 strikes again

* real
  • Loading branch information
Misha-133 authored Dec 13, 2024
1 parent d2d8d73 commit 438e31e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@ internal class AuditLogCache
public AuditLogCache(DiscordSocketClient client)
{
_size = client.AuditLogCacheSize;
var dictSize = _size;
if (dictSize * 1.05 > int.MaxValue)
dictSize = int.MaxValue;
else
dictSize = (int)(dictSize * 1.05);

_entries = new ConcurrentDictionary<ulong, SocketAuditLogEntry>(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(_size * 1.05));
_entries = new ConcurrentDictionary<ulong, SocketAuditLogEntry>(ConcurrentHashSet.DefaultConcurrencyLevel, dictSize);
_orderedEntries = new ConcurrentQueue<ulong>();
}

Expand Down
7 changes: 6 additions & 1 deletion src/Discord.Net.WebSocket/Entities/Messages/MessageCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ internal class MessageCache
public MessageCache(DiscordSocketClient discord)
{
_size = discord.MessageCacheSize;
_messages = new ConcurrentDictionary<ulong, SocketMessage>(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(_size * 1.05));
var dictSize = _size;
if (dictSize * 1.05 > int.MaxValue)
dictSize = int.MaxValue;
else
dictSize = (int)(dictSize * 1.05);
_messages = new ConcurrentDictionary<ulong, SocketMessage>(ConcurrentHashSet.DefaultConcurrencyLevel, dictSize);
_orderedMessages = new ConcurrentQueue<ulong>();
}

Expand Down

0 comments on commit 438e31e

Please sign in to comment.