Skip to content

Commit

Permalink
releaseb add IdGzipCacheSize
Browse files Browse the repository at this point in the history
  • Loading branch information
Sammers21 committed Jan 8, 2025
1 parent e8e9a47 commit 0e810fa
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/io/github/sammers/pla/logic/CharUpdater.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public Completable updateCharacters(String region,
merged.add(randomNotUpdatedIt.next());
}
}
characterCache.calculateSizeMetrics();
// merged into list of nickNames
log.info("There is {} new chars, {} existing chars and {} random not updated chars in region {} that need to be updated. We have {} {} to do it",
newCharsSorted.size(), existingSorted.size(), randomNotUpdatedChars.size(), region, timeout, timeoutUnits.name());
Expand Down
14 changes: 13 additions & 1 deletion src/io/github/sammers/pla/logic/CharacterCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.github.sammers.pla.blizzard.BracketType;
import io.github.sammers.pla.blizzard.WowAPICharacter;
import io.github.sammers.pla.db.Character;
import io.prometheus.metrics.core.metrics.Gauge;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
Expand All @@ -15,13 +16,24 @@ public class CharacterCache {
public final Map<Integer, Set<Long>> alts;
public final RealmStats realmStats;

public final Gauge idCacheSize = Gauge.builder()
.name("IdGzipCacheSize")
.help("How many characters are in the id cache")
.labelNames()
.register();

public CharacterCache() {
nameCache = new ConcurrentHashMap<>();
idCache = new ConcurrentHashMap<>();
alts = new ConcurrentHashMap<>();
realmStats = new RealmStats();
}

public void calculateSizeMetrics() {
long bytes = idCache.values().stream().mapToLong(b -> b.length).sum();
idCacheSize.set(bytes);
}

public WowAPICharacter getByFullName(String name) {
return WowAPICharacter.fromGzippedJson(nameCache.get(name));
}
Expand Down Expand Up @@ -91,7 +103,7 @@ public Set<WowAPICharacter> findAltsInconsistenciesAndFix(WowAPICharacter charac
WowAPICharacter changedAlts = ch.changeAlts(longs);
return changedAlts;
}).collect(Collectors.toSet());
return resm;
return resm;
}

public Collection<byte[]> values() {
Expand Down
6 changes: 4 additions & 2 deletions src/io/github/sammers/pla/logic/Ladder.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public class Ladder {
public final CharUpdater charUpdater;
private final DB db;
private final BlizzardAPI blizzardAPI;

private final AtomicBoolean charsLoaded = new AtomicBoolean(false);

public Ladder(WebClient web, DB db, BlizzardAPI blizzardAPI, CharacterCache characterCache, Refs refs, Map<String, Cutoffs> regionCutoff) {
Expand Down Expand Up @@ -576,7 +575,10 @@ public Completable loadWowCharApiData(String region) {
emitter.onComplete();
});
}));
});
}).andThen(Completable.defer(() -> {
characterCache.calculateSizeMetrics();
return Completable.complete();
}));
}

private Completable loadLast(String bracket, String region) {
Expand Down

0 comments on commit 0e810fa

Please sign in to comment.