mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-13 01:00:12 +00:00
feat: cache Discord DM channels in database
This commit is contained in:
parent
ddbf0e8691
commit
89c44a3482
14 changed files with 127 additions and 48 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue