From ba699f53051072381bfbb3e3ea2400c64f34a693 Mon Sep 17 00:00:00 2001 From: Liam Date: Thu, 18 Apr 2024 17:07:55 +0100 Subject: [PATCH] store uuid instead of query for unique player lookup total --- .../xyz/mcutils/backend/service/PlayerService.java | 3 +-- .../metric/metrics/UniquePlayerLookupsMetric.java | 10 +++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/java/xyz/mcutils/backend/service/PlayerService.java b/src/main/java/xyz/mcutils/backend/service/PlayerService.java index e5dc913..19d5f6a 100644 --- a/src/main/java/xyz/mcutils/backend/service/PlayerService.java +++ b/src/main/java/xyz/mcutils/backend/service/PlayerService.java @@ -61,8 +61,6 @@ public class PlayerService { uuid = usernameToUuid(id).getUniqueId(); } - ((UniquePlayerLookupsMetric) metricService.getMetric(UniquePlayerLookupsMetric.class)).addLookup(id); // Add the lookup to the unique player lookups - Optional cachedPlayer = playerCacheRepository.findById(uuid); if (cachedPlayer.isPresent() && EnvironmentUtils.isProduction()) { // Return the cached player if it exists log.info("Player {} is cached", id); @@ -85,6 +83,7 @@ public class PlayerService { mojangProfile.getProperties() // Raw properties ) ); + ((UniquePlayerLookupsMetric) metricService.getMetric(UniquePlayerLookupsMetric.class)).addLookup(uuid); // Add the lookup to the unique player lookups playerCacheRepository.save(player); player.getCache().setCached(false); diff --git a/src/main/java/xyz/mcutils/backend/service/metric/metrics/UniquePlayerLookupsMetric.java b/src/main/java/xyz/mcutils/backend/service/metric/metrics/UniquePlayerLookupsMetric.java index e62bc4f..3f9eab4 100644 --- a/src/main/java/xyz/mcutils/backend/service/metric/metrics/UniquePlayerLookupsMetric.java +++ b/src/main/java/xyz/mcutils/backend/service/metric/metrics/UniquePlayerLookupsMetric.java @@ -4,6 +4,7 @@ import xyz.mcutils.backend.service.metric.impl.IntegerMetric; import java.util.ArrayList; import java.util.List; +import java.util.UUID; public class UniquePlayerLookupsMetric extends IntegerMetric { private List uniqueLookups = new ArrayList<>(); @@ -20,12 +21,11 @@ public class UniquePlayerLookupsMetric extends IntegerMetric { /** * Adds a lookup to the list of unique lookups. * - * @param lookup the query that was used to look up a player + * @param uuid 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(UUID uuid) { + if (!uniqueLookups.contains(uuid.toString())) { + uniqueLookups.add(uuid.toString()); } }