add total player and server lookups
All checks were successful
Deploy App / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Successful in 1m48s
All checks were successful
Deploy App / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Successful in 1m48s
This commit is contained in:
@ -24,6 +24,8 @@ import xyz.mcutils.backend.model.token.MojangUsernameToUuidToken;
|
||||
import xyz.mcutils.backend.repository.PlayerCacheRepository;
|
||||
import xyz.mcutils.backend.repository.PlayerNameCacheRepository;
|
||||
import xyz.mcutils.backend.repository.PlayerSkinPartCacheRepository;
|
||||
import xyz.mcutils.backend.service.metric.metrics.TotalPlayerLookupsMetric;
|
||||
import xyz.mcutils.backend.service.metric.metrics.TotalServerLookupsMetric;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Optional;
|
||||
@ -33,14 +35,16 @@ import java.util.UUID;
|
||||
public class PlayerService {
|
||||
|
||||
private final MojangService mojangAPIService;
|
||||
private final MetricService metricService;
|
||||
private final PlayerCacheRepository playerCacheRepository;
|
||||
private final PlayerNameCacheRepository playerNameCacheRepository;
|
||||
private final PlayerSkinPartCacheRepository playerSkinPartCacheRepository;
|
||||
|
||||
@Autowired
|
||||
public PlayerService(MojangService mojangAPIService, PlayerCacheRepository playerCacheRepository,
|
||||
public PlayerService(MojangService mojangAPIService, MetricService metricService, PlayerCacheRepository playerCacheRepository,
|
||||
PlayerNameCacheRepository playerNameCacheRepository, PlayerSkinPartCacheRepository playerSkinPartCacheRepository) {
|
||||
this.mojangAPIService = mojangAPIService;
|
||||
this.metricService = metricService;
|
||||
this.playerCacheRepository = playerCacheRepository;
|
||||
this.playerNameCacheRepository = playerNameCacheRepository;
|
||||
this.playerSkinPartCacheRepository = playerSkinPartCacheRepository;
|
||||
@ -61,6 +65,8 @@ public class PlayerService {
|
||||
uuid = usernameToUuid(id).getUniqueId();
|
||||
}
|
||||
|
||||
((TotalPlayerLookupsMetric) metricService.getMetric(TotalPlayerLookupsMetric.class)).increment(); // Increment the total player lookups
|
||||
|
||||
Optional<CachedPlayer> cachedPlayer = playerCacheRepository.findById(uuid);
|
||||
if (cachedPlayer.isPresent() && Config.INSTANCE.isProduction()) { // Return the cached player if it exists
|
||||
log.info("Player {} is cached", id);
|
||||
|
Reference in New Issue
Block a user