From 7a1ffc0538b3a1be594972be488a8f0075c2c53b Mon Sep 17 00:00:00 2001 From: Liam Date: Sat, 6 Jul 2024 21:14:20 +0100 Subject: [PATCH] update cache expiration policy --- .../bat/features/logging/listeners/GuildListener.java | 2 +- .../features/scoresaber/command/userfeed/UserFeedCommand.java | 4 ++-- .../features/scoresaber/command/userfeed/UserSubCommand.java | 4 +--- src/main/java/cc/fascinated/bat/service/UserService.java | 2 ++ 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/cc/fascinated/bat/features/logging/listeners/GuildListener.java b/src/main/java/cc/fascinated/bat/features/logging/listeners/GuildListener.java index 2ad679e..6678974 100644 --- a/src/main/java/cc/fascinated/bat/features/logging/listeners/GuildListener.java +++ b/src/main/java/cc/fascinated/bat/features/logging/listeners/GuildListener.java @@ -49,8 +49,8 @@ public class GuildListener implements EventListener { "<#%s>".formatted(expandedInvite.getChannel().getId()) : expandedInvite.getChannel().getName() ), true); } - description.appendLine("Max Uses: `%s`".formatted(expandedInvite.getMaxUses() == 0 ? "Infinite" : expandedInvite.getMaxUses()), true); description.appendLine("Creator: %s".formatted(expandedInvite.getInviter() == null ? "Unknown" : expandedInvite.getInviter().getAsMention()), true); + description.appendLine("Max Uses: `%s`".formatted(expandedInvite.getMaxUses() == 0 ? "Infinite" : expandedInvite.getMaxUses()), true); ; logFeature.sendLog(guild, LogType.INVITE_CREATE, EmbedUtils.successEmbed().setDescription(description.build()).build()); }); diff --git a/src/main/java/cc/fascinated/bat/features/scoresaber/command/userfeed/UserFeedCommand.java b/src/main/java/cc/fascinated/bat/features/scoresaber/command/userfeed/UserFeedCommand.java index a994de7..75d945f 100644 --- a/src/main/java/cc/fascinated/bat/features/scoresaber/command/userfeed/UserFeedCommand.java +++ b/src/main/java/cc/fascinated/bat/features/scoresaber/command/userfeed/UserFeedCommand.java @@ -18,7 +18,7 @@ public class UserFeedCommand extends BatCommand { super.addSubCommands( context.getBean(UserSubCommand.class), context.getBean(ChannelSubCommand.class), - context.getBean(ResetSubCommand.class - )); + context.getBean(ResetSubCommand.class) + ); } } diff --git a/src/main/java/cc/fascinated/bat/features/scoresaber/command/userfeed/UserSubCommand.java b/src/main/java/cc/fascinated/bat/features/scoresaber/command/userfeed/UserSubCommand.java index 71a75a5..542abc1 100644 --- a/src/main/java/cc/fascinated/bat/features/scoresaber/command/userfeed/UserSubCommand.java +++ b/src/main/java/cc/fascinated/bat/features/scoresaber/command/userfeed/UserSubCommand.java @@ -26,13 +26,11 @@ import org.springframework.stereotype.Component; @Component("scoresaber-user-feed:user.sub") @CommandInfo(name = "user", description = "Adds or removes a user from the feed") public class UserSubCommand extends BatCommand { - private final GuildService guildService; private final UserService userService; @Autowired - public UserSubCommand(GuildService guildService, UserService userService) { + public UserSubCommand(UserService userService) { super.addOptions(new OptionData(OptionType.USER, "user", "Add or remove a user from the score feed", false)); - this.guildService = guildService; this.userService = userService; } diff --git a/src/main/java/cc/fascinated/bat/service/UserService.java b/src/main/java/cc/fascinated/bat/service/UserService.java index 8320958..ca3513a 100644 --- a/src/main/java/cc/fascinated/bat/service/UserService.java +++ b/src/main/java/cc/fascinated/bat/service/UserService.java @@ -11,6 +11,7 @@ import lombok.extern.log4j.Log4j2; import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent; import net.dv8tion.jda.api.events.user.update.UserUpdateGlobalNameEvent; +import net.jodah.expiringmap.ExpirationPolicy; import net.jodah.expiringmap.ExpiringMap; import org.bson.Document; import org.springframework.beans.factory.annotation.Autowired; @@ -36,6 +37,7 @@ public class UserService implements EventListener { */ private final Map users = ExpiringMap.builder() .expiration(1, TimeUnit.HOURS) + .expirationPolicy(ExpirationPolicy.ACCESSED) // Expire after not being accessed for 1 hour .expirationListener((key, cachedUser) -> { BatUser user = (BatUser) cachedUser; log.info("Removed user \"{}\" - \"{}\" from cache", user.getName(), user.getId());