feat: cache Discord DM channels in database

This commit is contained in:
spiral 2022-01-22 02:47:47 -05:00
parent ddbf0e8691
commit 89c44a3482
No known key found for this signature in database
GPG key ID: A6059F0CA0E1BD31
14 changed files with 127 additions and 48 deletions

View file

@ -7,7 +7,6 @@ namespace Myriad.Cache;
public class MemoryDiscordCache: IDiscordCache
{
private readonly ConcurrentDictionary<ulong, Channel> _channels = new();
private readonly ConcurrentDictionary<ulong, ulong> _dmChannels = new();
private readonly ConcurrentDictionary<ulong, GuildMemberPartial> _guildMembers = new();
private readonly ConcurrentDictionary<ulong, CachedGuild> _guilds = new();
private readonly ConcurrentDictionary<ulong, Role> _roles = new();
@ -35,10 +34,7 @@ public class MemoryDiscordCache: IDiscordCache
if (channel.Recipients != null)
foreach (var recipient in channel.Recipients)
{
_dmChannels[recipient.Id] = channel.Id;
await SaveUser(recipient);
}
}
public ValueTask SaveOwnUser(ulong userId)
@ -140,13 +136,6 @@ public class MemoryDiscordCache: IDiscordCache
return Task.FromResult(channel);
}
public Task<Channel?> TryGetDmChannel(ulong userId)
{
if (!_dmChannels.TryGetValue(userId, out var channelId))
return Task.FromResult((Channel?)null);
return TryGetChannel(channelId);
}
public Task<User?> TryGetUser(ulong userId)
{
_users.TryGetValue(userId, out var user);