From 131a364f5388121fbf90de7f0da8be4829eda5cc Mon Sep 17 00:00:00 2001 From: William278 Date: Tue, 13 Feb 2024 14:38:19 +0000 Subject: [PATCH] fix: cache not cleared on `/userdata delete`, close #245 --- .../william278/husksync/command/UserDataCommand.java | 3 ++- .../net/william278/husksync/redis/RedisManager.java | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/net/william278/husksync/command/UserDataCommand.java b/common/src/main/java/net/william278/husksync/command/UserDataCommand.java index 7b06f06a..846bdd47 100644 --- a/common/src/main/java/net/william278/husksync/command/UserDataCommand.java +++ b/common/src/main/java/net/william278/husksync/command/UserDataCommand.java @@ -112,13 +112,14 @@ public class UserDataCommand extends Command implements TabProvider { return; } - // Delete user data by specified UUID + // Delete user data by specified UUID and clear their data cache final UUID version = optionalUuid.get(); if (!plugin.getDatabase().deleteSnapshot(user, version)) { plugin.getLocales().getLocale("error_invalid_version_uuid") .ifPresent(executor::sendMessage); return; } + plugin.getRedisManager().clearUserData(user); plugin.getLocales().getLocale("data_deleted", version.toString().split("-")[0], diff --git a/common/src/main/java/net/william278/husksync/redis/RedisManager.java b/common/src/main/java/net/william278/husksync/redis/RedisManager.java index e91aa9b9..5dbed40a 100644 --- a/common/src/main/java/net/william278/husksync/redis/RedisManager.java +++ b/common/src/main/java/net/william278/husksync/redis/RedisManager.java @@ -255,6 +255,18 @@ public class RedisManager extends JedisPubSub { } } + @Blocking + public void clearUserData(@NotNull User user) { + try (Jedis jedis = jedisPool.getResource()) { + jedis.del( + getKey(RedisKeyType.LATEST_SNAPSHOT, user.getUuid(), clusterId) + ); + plugin.debug(String.format("[%s] Cleared %s on Redis", user.getUsername(), RedisKeyType.LATEST_SNAPSHOT)); + } catch (Throwable e) { + plugin.log(Level.SEVERE, "An exception occurred clearing user data on Redis", e); + } + } + @Blocking public void setUserCheckedOut(@NotNull User user, boolean checkedOut) { try (Jedis jedis = jedisPool.getResource()) {