fix the fixy
All checks were successful
Deploy App / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Successful in 1m59s

This commit is contained in:
Lee 2024-04-18 16:47:48 +01:00
parent cb9181010a
commit b3e560d1e2
6 changed files with 27 additions and 19 deletions

View File

@ -0,0 +1,17 @@
package xyz.mcutils.backend.common;
import lombok.Getter;
import lombok.experimental.UtilityClass;
@UtilityClass
public final class EnvironmentUtils {
/**
* Is the app running in a production environment?
*/
@Getter
private static final boolean production;
static { // Are we running on production?
String env = System.getenv("ENVIRONMENT");
production = env != null && (env.equals("production"));
}
}

View File

@ -23,18 +23,9 @@ public class Config {
@Value("${public-url}")
private String webPublicUrl;
/**
* Whether the server is in production mode.
*/
private boolean production = false;
@PostConstruct
public void onInitialize() {
INSTANCE = this;
String environmentProperty = environment.getProperty("ENVIRONMENT", "development");
production = environmentProperty.equalsIgnoreCase("production"); // Set the production mode
log.info("Server is running in {} mode", production ? "production" : "development");
}
@Bean

View File

@ -6,6 +6,7 @@ import com.influxdb.spring.influx.InfluxDB2AutoConfiguration;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import xyz.mcutils.backend.common.EnvironmentUtils;
import xyz.mcutils.backend.common.Timer;
import xyz.mcutils.backend.config.Config;
import xyz.mcutils.backend.repository.mongo.MetricsRepository;
@ -56,7 +57,7 @@ public class MetricService {
collectorEnabled.put(metric, metric.isCollector());
}
if (Config.INSTANCE.isProduction()) {
if (EnvironmentUtils.isProduction()) {
// Load the metrics from Redis
loadMetrics();

View File

@ -15,6 +15,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import xyz.mcutils.backend.Main;
import xyz.mcutils.backend.common.Endpoint;
import xyz.mcutils.backend.common.EnvironmentUtils;
import xyz.mcutils.backend.common.ExpiringSet;
import xyz.mcutils.backend.common.WebRequest;
import xyz.mcutils.backend.config.Config;
@ -190,7 +191,7 @@ public class MojangService {
public CachedEndpointStatus getMojangApiStatus() {
log.info("Getting Mojang API status");
Optional<CachedEndpointStatus> endpointStatus = mojangEndpointStatusRepository.findById(MOJANG_ENDPOINT_STATUS_KEY);
if (endpointStatus.isPresent() && Config.INSTANCE.isProduction()) {
if (endpointStatus.isPresent() && EnvironmentUtils.isProduction()) {
log.info("Got cached Mojang API status");
return endpointStatus.get();
}

View File

@ -3,10 +3,7 @@ package xyz.mcutils.backend.service;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import xyz.mcutils.backend.common.ImageUtils;
import xyz.mcutils.backend.common.PlayerUtils;
import xyz.mcutils.backend.common.Tuple;
import xyz.mcutils.backend.common.UUIDUtils;
import xyz.mcutils.backend.common.*;
import xyz.mcutils.backend.config.Config;
import xyz.mcutils.backend.exception.impl.BadRequestException;
import xyz.mcutils.backend.exception.impl.MojangAPIRateLimitException;
@ -67,7 +64,7 @@ public class PlayerService {
((UniquePlayerLookupsMetric) metricService.getMetric(UniquePlayerLookupsMetric.class)).addLookup(id); // Add the lookup to the unique player lookups
Optional<CachedPlayer> cachedPlayer = playerCacheRepository.findById(uuid);
if (cachedPlayer.isPresent() && Config.INSTANCE.isProduction()) { // Return the cached player if it exists
if (cachedPlayer.isPresent() && EnvironmentUtils.isProduction()) { // Return the cached player if it exists
log.info("Player {} is cached", id);
return cachedPlayer.get();
}
@ -107,7 +104,7 @@ public class PlayerService {
log.info("Getting UUID from username: {}", username);
String id = username.toUpperCase();
Optional<CachedPlayerName> cachedPlayerName = playerNameCacheRepository.findById(id);
if (cachedPlayerName.isPresent() && Config.INSTANCE.isProduction()) {
if (cachedPlayerName.isPresent() && EnvironmentUtils.isProduction()) {
return cachedPlayerName.get();
}
try {
@ -157,7 +154,7 @@ public class PlayerService {
Optional<CachedPlayerSkinPart> cache = playerSkinPartCacheRepository.findById(key);
// The skin part is cached
if (cache.isPresent() && Config.INSTANCE.isProduction()) {
if (cache.isPresent() && EnvironmentUtils.isProduction()) {
log.info("Skin part {} for player {} is cached", name, player.getUniqueId());
return cache.get();
}

View File

@ -5,6 +5,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import xyz.mcutils.backend.common.DNSUtils;
import xyz.mcutils.backend.common.EnumUtils;
import xyz.mcutils.backend.common.EnvironmentUtils;
import xyz.mcutils.backend.config.Config;
import xyz.mcutils.backend.exception.impl.BadRequestException;
import xyz.mcutils.backend.exception.impl.ResourceNotFoundException;
@ -69,7 +70,7 @@ public class ServerService {
// Check if the server is cached
Optional<CachedMinecraftServer> cached = serverCacheRepository.findById(key);
if (cached.isPresent() && Config.INSTANCE.isProduction()) {
if (cached.isPresent() && EnvironmentUtils.isProduction()) {
log.info("Server {}:{} is cached", hostname, port);
return cached.get();
}