feat: also clear cache when leaving a guild without deleting data
This commit is contained in:
parent
439051999f
commit
ce323096e6
1 changed files with 14 additions and 7 deletions
|
|
@ -31,11 +31,12 @@ public class GuildCreateResponder(
|
|||
ILogger logger,
|
||||
DatabaseContext db,
|
||||
GuildCache guildCache,
|
||||
RoleCache roleCache,
|
||||
ChannelCache channelCache,
|
||||
EmojiCache emojiCache,
|
||||
WebhookExecutorService webhookExecutor,
|
||||
ChannelCache channelCache,
|
||||
RoleCache roleCache,
|
||||
IMemberCache memberCache,
|
||||
IInviteCache inviteCache,
|
||||
WebhookExecutorService webhookExecutor,
|
||||
GuildFetchService guildFetchService
|
||||
) : IResponder<IGuildCreate>, IResponder<IGuildDelete>
|
||||
{
|
||||
|
|
@ -102,20 +103,26 @@ public class GuildCreateResponder(
|
|||
return Result.Success;
|
||||
}
|
||||
|
||||
public Task<Result> RespondAsync(IGuildDelete evt, CancellationToken ct = default)
|
||||
public async Task<Result> RespondAsync(IGuildDelete evt, CancellationToken ct = default)
|
||||
{
|
||||
if (evt.IsUnavailable.OrDefault(false))
|
||||
{
|
||||
_logger.Debug("Guild {GuildId} became unavailable", evt.ID);
|
||||
return Task.FromResult(Result.Success);
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
// Clear the cache for this guild
|
||||
guildCache.Remove(evt.ID, out _);
|
||||
emojiCache.Remove(evt.ID);
|
||||
channelCache.RemoveGuild(evt.ID);
|
||||
roleCache.RemoveGuild(evt.ID);
|
||||
await memberCache.RemoveAllMembersAsync(evt.ID);
|
||||
await inviteCache.RemoveAsync(evt.ID);
|
||||
|
||||
if (!guildCache.TryGet(evt.ID, out var guild))
|
||||
{
|
||||
_logger.Information("Left uncached guild {GuildId}", evt.ID);
|
||||
return Task.FromResult(Result.Success);
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
_logger.Information("Left guild {GuildName} / {GuildId}", guild.Name, guild.ID);
|
||||
|
|
@ -135,6 +142,6 @@ public class GuildCreateResponder(
|
|||
.GetOrThrow()
|
||||
);
|
||||
|
||||
return Task.FromResult(Result.Success);
|
||||
return Result.Success;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue