From 8dcde443ee8c63a54912e0a492fa771ed1af6b37 Mon Sep 17 00:00:00 2001 From: Liam Date: Thu, 18 Apr 2024 17:08:07 +0100 Subject: [PATCH] store hostname instead of query for unique server lookup total --- .../xyz/mcutils/backend/service/ServerService.java | 4 ++-- .../metric/metrics/UniqueServerLookupsMetric.java | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/xyz/mcutils/backend/service/ServerService.java b/src/main/java/xyz/mcutils/backend/service/ServerService.java index e5df3a0..5e57409 100644 --- a/src/main/java/xyz/mcutils/backend/service/ServerService.java +++ b/src/main/java/xyz/mcutils/backend/service/ServerService.java @@ -66,8 +66,6 @@ public class ServerService { String key = "%s-%s:%s".formatted(platformName, hostname, port); log.info("Getting server: {}:{}", hostname, port); - ((UniqueServerLookupsMetric) metricService.getMetric(UniqueServerLookupsMetric.class)).addLookup(key); // Add the server lookup to the unique server lookups - // Check if the server is cached Optional cached = serverCacheRepository.findById(key); if (cached.isPresent() && EnvironmentUtils.isProduction()) { @@ -102,6 +100,8 @@ public class ServerService { ((JavaMinecraftServer) server.getServer()).setMojangBlocked(mojangService.isServerBlocked(hostname)); } + ((UniqueServerLookupsMetric) metricService.getMetric(UniqueServerLookupsMetric.class)).addLookup(key); // Add the server lookup to the unique server lookups + log.info("Found server: {}:{}", hostname, port); serverCacheRepository.save(server); server.getCache().setCached(false); diff --git a/src/main/java/xyz/mcutils/backend/service/metric/metrics/UniqueServerLookupsMetric.java b/src/main/java/xyz/mcutils/backend/service/metric/metrics/UniqueServerLookupsMetric.java index 12921cc..6a8060a 100644 --- a/src/main/java/xyz/mcutils/backend/service/metric/metrics/UniqueServerLookupsMetric.java +++ b/src/main/java/xyz/mcutils/backend/service/metric/metrics/UniqueServerLookupsMetric.java @@ -20,12 +20,12 @@ public class UniqueServerLookupsMetric extends IntegerMetric { /** * Adds a lookup to the list of unique lookups. * - * @param lookup the query that was used to look up a player + * @param hostname the query that was used to look up a player */ - public void addLookup(String lookup) { - lookup = lookup.toLowerCase(); - if (!uniqueLookups.contains(lookup)) { - uniqueLookups.add(lookup); + public void addLookup(String hostname) { + hostname = hostname.toLowerCase(); + if (!uniqueLookups.contains(hostname)) { + uniqueLookups.add(hostname); } }