Skip to content

Commit

Permalink
fix: cache not cleared on /userdata delete, close #245
Browse files Browse the repository at this point in the history
  • Loading branch information
WiIIiam278 committed Feb 13, 2024
1 parent 19636d9 commit 131a364
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,14 @@ public void execute(@NotNull CommandUser executor, @NotNull String[] args) {
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],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,18 @@ public void setUserData(@NotNull User user, @NotNull DataSnapshot.Packed data, i
}
}

@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()) {
Expand Down

0 comments on commit 131a364

Please sign in to comment.