clean up cache info
Some checks failed
Deploy App / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Failing after 22s

This commit is contained in:
Lee 2024-04-13 17:17:13 +01:00
parent c198339acc
commit 8216ec7943
8 changed files with 51 additions and 32 deletions

@ -8,25 +8,27 @@ import org.springframework.data.redis.core.RedisHash;
import java.io.Serializable; import java.io.Serializable;
import java.util.Map; import java.util.Map;
@AllArgsConstructor @Setter @Getter @ToString @Setter @Getter @ToString
@NoArgsConstructor
@RedisHash(value = "mojangEndpointStatus", timeToLive = 60L) // 1 minute (in seconds) @RedisHash(value = "mojangEndpointStatus", timeToLive = 60L) // 1 minute (in seconds)
public final class CachedEndpointStatus implements Serializable { public final class CachedEndpointStatus extends CachedResponse implements Serializable {
/** /**
* The id for this endpoint cache. * The id for this endpoint cache.
*/ */
@Id @NonNull @JsonIgnore @Id @NonNull @JsonIgnore
private final String id; private String id;
/** /**
* The list of endpoints and their status. * The list of endpoints and their status.
*/ */
private final Map<String, Status> endpoints; private Map<String, Status> endpoints;
/** public CachedEndpointStatus(@NonNull String id, Map<String, Status> endpoints) {
* The cache information about the request. super(CacheInformation.defaultCache());
*/ this.id = id;
private CacheInformation cache; this.endpoints = endpoints;
}
public enum Status { public enum Status {
/** /**

@ -11,23 +11,25 @@ import java.io.Serializable;
/** /**
* @author Braydon * @author Braydon
*/ */
@AllArgsConstructor @Setter @Getter @ToString @Setter @Getter @ToString
@NoArgsConstructor
@RedisHash(value = "server", timeToLive = 60L) // 1 minute (in seconds) @RedisHash(value = "server", timeToLive = 60L) // 1 minute (in seconds)
public final class CachedMinecraftServer implements Serializable { public final class CachedMinecraftServer extends CachedResponse implements Serializable {
/** /**
* The id of this cached server. * The id of this cached server.
*/ */
@Id @NonNull @JsonIgnore @Id @NonNull @JsonIgnore
private final String id; private String id;
/** /**
* The cached server. * The cached server.
*/ */
@NonNull @NonNull
private final MinecraftServer server; private MinecraftServer server;
/** public CachedMinecraftServer(@NonNull String id, @NonNull MinecraftServer server) {
* The cache information about the request. super(CacheInformation.defaultCache());
*/ this.id = id;
private CacheInformation cache; this.server = server;
}
} }

@ -4,6 +4,7 @@ import cc.fascinated.model.player.Player;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
import org.springframework.data.annotation.Id; import org.springframework.data.annotation.Id;
import org.springframework.data.redis.core.RedisHash; import org.springframework.data.redis.core.RedisHash;
@ -17,9 +18,9 @@ import java.util.UUID;
* @author Braydon * @author Braydon
*/ */
@Setter @Getter @Setter @Getter
@AllArgsConstructor @NoArgsConstructor
@RedisHash(value = "player", timeToLive = 60L * 60L) // 1 hour (in seconds) @RedisHash(value = "player", timeToLive = 60L * 60L) // 1 hour (in seconds)
public final class CachedPlayer implements Serializable { public final class CachedPlayer extends CachedResponse implements Serializable {
/** /**
* The unique id of the player. * The unique id of the player.
*/ */
@ -31,8 +32,9 @@ public final class CachedPlayer implements Serializable {
*/ */
private Player player; private Player player;
/** public CachedPlayer(UUID uniqueId, Player player) {
* The cache information about the request. super(CacheInformation.defaultCache());
*/ this.uniqueId = uniqueId;
private CacheInformation cache; this.player = player;
}
} }

@ -0,0 +1,15 @@
package cc.fascinated.model.cache;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
@AllArgsConstructor @NoArgsConstructor
@Getter
public class CachedResponse {
/**
* The cache information for this response.
*/
private CacheInformation cache;
}

@ -6,26 +6,27 @@ import cc.fascinated.model.mojang.MojangProfile;
import cc.fascinated.model.skin.Skin; import cc.fascinated.model.skin.Skin;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor;
import java.util.UUID; import java.util.UUID;
@Getter @AllArgsConstructor @Getter @AllArgsConstructor @NoArgsConstructor
public class Player { public class Player {
/** /**
* The UUID of the player * The UUID of the player
*/ */
private final UUID uniqueId; private UUID uniqueId;
/** /**
* The trimmed UUID of the player * The trimmed UUID of the player
*/ */
private final String trimmedUniqueId; private String trimmedUniqueId;
/** /**
* The username of the player * The username of the player
*/ */
private final String username; private String username;
/** /**
* The skin of the player, null if the * The skin of the player, null if the

@ -231,8 +231,7 @@ public class MojangService {
log.info("Fetched Mojang API status for {} endpoints", endpoints.size()); log.info("Fetched Mojang API status for {} endpoints", endpoints.size());
CachedEndpointStatus status = new CachedEndpointStatus( CachedEndpointStatus status = new CachedEndpointStatus(
MOJANG_ENDPOINT_STATUS_KEY, MOJANG_ENDPOINT_STATUS_KEY,
endpoints, endpoints
CacheInformation.defaultCache()
); );
mojangEndpointStatusRepository.save(status); mojangEndpointStatusRepository.save(status);
status.getCache().setCached(false); status.getCache().setCached(false);

@ -82,8 +82,7 @@ public class PlayerService {
skinAndCape.getLeft(), // Skin skinAndCape.getLeft(), // Skin
skinAndCape.getRight(), // Cape skinAndCape.getRight(), // Cape
mojangProfile.getProperties() // Raw properties mojangProfile.getProperties() // Raw properties
), )
CacheInformation.defaultCache() // Cache time
); );
playerCacheRepository.save(player); playerCacheRepository.save(player);

@ -89,8 +89,7 @@ public class ServerService {
CachedMinecraftServer server = new CachedMinecraftServer( CachedMinecraftServer server = new CachedMinecraftServer(
key, key,
platform.getPinger().ping(hostname, ip, port, records.toArray(new DNSRecord[0])), platform.getPinger().ping(hostname, ip, port, records.toArray(new DNSRecord[0]))
CacheInformation.defaultCache()
); );
// Check if the server is blocked by Mojang // Check if the server is blocked by Mojang