Skip to content

Commit

Permalink
releaseb calculate meta in a separated virtual thread
Browse files Browse the repository at this point in the history
  • Loading branch information
Sammers21 committed Sep 23, 2023
1 parent c4225e7 commit 8b0af97
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/io/github/sammers/pla/logic/Ladder.java
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,6 @@ public Single<Snapshot> fetchLadder(String bracket, String region) {
return fetchLadder(bracket, region, true);
}

public Completable calcAlts(){
return Completable.fromAction(() -> Calculator.calculateAlts(characterCache.values(), alts));
}

public Single<List<Character>> pureBlizzardApiFetch(String bracket, String region){
Single<List<Character>> resCharList;
if (bracket.equals(SHUFFLE)) {
Expand Down Expand Up @@ -532,16 +528,21 @@ private Completable calculateMeta(String region) {
diff = db.getMinsAgo(bracket, region, minsAgo)
.map(snap -> Calculator.calculateDiff(snap, now, bracket, false));
}
return Stream.of(diff.map(realDiff -> {
return Stream.of(diff.flatMapCompletable(realDiff -> {
try {
Meta meta = Calculator.calculateMeta(realDiff, role, bracket, 0.05, 0.10, 0.85);
metaRef(bracket, realRegion, role, period).set(meta);
return meta;
VTHREAD_SCHEDULER.scheduleDirect(() -> {
long tick = System.nanoTime();
Meta meta = Calculator.calculateMeta(realDiff, role, bracket, 0.05, 0.10, 0.85);
metaRef(bracket, realRegion, role, period).set(meta);
long elapsed = (System.nanoTime() - tick) / 1000000;
log.info("Meta for bracket={} region={} role={} period={} has been calculated in {} ms", bracket, region, role, period, elapsed);
});
return Completable.complete();
} catch (Exception e) {
log.error("Error calculating meta for " + bracket + " " + region + " " + role + " " + period, e);
return new Meta(Map.of(), Map.of(), List.of());
return Completable.error(e);
}
}).ignoreElement().onErrorComplete());
}).onErrorComplete());
}));
}).collect(Collectors.toList());
return Completable.merge(res);
Expand Down

0 comments on commit 8b0af97

Please sign in to comment.