Merge pull request 'fix: cache refresh v2' (#123) from dev into master
Reviewed-on: #123
This commit is contained in:
commit
72f8a27272
@ -58,6 +58,7 @@ public class ResultService {
|
||||
@Inject
|
||||
@CacheName("club-classement")
|
||||
Cache cacheClubClassement;
|
||||
private static final HashMap<String, Long> cacheClubClassementExp = new HashMap<>();
|
||||
|
||||
private static final HashMap<Long, String> combTempIds = new HashMap<>();
|
||||
|
||||
@ -754,88 +755,87 @@ public class ResultService {
|
||||
public Uni<List<ClubClassement>> getAllClubArray(String uuid, boolean cache) {
|
||||
List<CardModel> cards = new java.util.ArrayList<>();
|
||||
|
||||
//noinspection unchecked
|
||||
return cacheClubClassement.invalidateIf(
|
||||
(p) -> ((Pair<Long, List<ClubClassement>>) p).getKey() > System.currentTimeMillis())
|
||||
.chain(__ -> cache ? Uni.createFrom().voidItem() : cacheClubClassement.invalidate(uuid))
|
||||
.chain(o -> cacheClubClassement.getAsync(uuid, k -> cardRepository.list("competition.uuid = ?1", uuid)
|
||||
.invoke(__ -> System.out.println("Cache miss for club classement with uuid " + uuid))
|
||||
.invoke(cards::addAll)
|
||||
.chain(__ -> matchRepository.list("category.compet.uuid = ?1", uuid))
|
||||
.chain(matchs -> {
|
||||
HashMap<CategoryModel, List<MatchModel>> map = new HashMap<>();
|
||||
for (MatchModel match : matchs) {
|
||||
if (!map.containsKey(match.getCategory()))
|
||||
map.put(match.getCategory(), new java.util.ArrayList<>());
|
||||
map.get(match.getCategory()).add(match);
|
||||
return (!cache || cacheClubClassementExp.getOrDefault(uuid, 0L) < System.currentTimeMillis() ?
|
||||
cacheClubClassement.invalidate(uuid).invoke(() -> cacheClubClassementExp.remove(uuid)) :
|
||||
Uni.createFrom().voidItem()
|
||||
).chain(o -> cacheClubClassement.getAsync(uuid, k -> cardRepository.list("competition.uuid = ?1", uuid)
|
||||
.invoke(__ -> System.out.println("Cache miss for club classement with uuid " + uuid))
|
||||
.invoke(cards::addAll)
|
||||
.chain(__ -> matchRepository.list("category.compet.uuid = ?1", uuid))
|
||||
.chain(matchs -> {
|
||||
HashMap<CategoryModel, List<MatchModel>> map = new HashMap<>();
|
||||
for (MatchModel match : matchs) {
|
||||
if (!map.containsKey(match.getCategory()))
|
||||
map.put(match.getCategory(), new java.util.ArrayList<>());
|
||||
map.get(match.getCategory()).add(match);
|
||||
}
|
||||
|
||||
return Multi.createFrom().iterable(map.entrySet())
|
||||
.onItem().call(entry -> Mutiny.fetch(entry.getKey().getTree()))
|
||||
.map(entry -> {
|
||||
ResultCategoryData tmp = new ResultCategoryData();
|
||||
|
||||
getArray2(entry.getValue().stream().map(m -> new MatchModelExtend(m, cards))
|
||||
.toList(),
|
||||
null, tmp);
|
||||
getClassementArray(entry.getKey(), null, cards, tmp);
|
||||
|
||||
return tmp;
|
||||
})
|
||||
.collect().asList();
|
||||
})
|
||||
.map(categoryData -> {
|
||||
HashMap<String, ClubClassement> clubMap = new HashMap<>();
|
||||
|
||||
categoryData.forEach(
|
||||
c -> c.getClassement().stream().map(ResultCategoryData.ClassementData::comb)
|
||||
.filter(Objects::nonNull)
|
||||
.distinct()
|
||||
.map(comb -> {
|
||||
if (comb instanceof MembreModel membreModel2) {
|
||||
return (membreModel2.getClub() != null) ? membreModel2.getClub()
|
||||
.getName() : "";
|
||||
} else if (comb instanceof CompetitionGuestModel guestModel) {
|
||||
return guestModel.getClub();
|
||||
}
|
||||
return "";
|
||||
})
|
||||
.filter(s -> s != null && !s.isBlank() && !s.equals("Team"))
|
||||
.distinct()
|
||||
.forEach(clubName -> clubMap.putIfAbsent(clubName,
|
||||
new ClubClassement(clubName))));
|
||||
|
||||
categoryData.forEach(c -> c.getClassement().forEach(classementData -> {
|
||||
if (classementData.rank() > 3)
|
||||
return;
|
||||
|
||||
if (classementData.comb() != null) {
|
||||
String clubName = "";
|
||||
if (classementData.comb() instanceof MembreModel membreModel2) {
|
||||
clubName = (membreModel2.getClub() != null) ? membreModel2.getClub()
|
||||
.getName() : "";
|
||||
} else if (classementData.comb() instanceof CompetitionGuestModel guestModel) {
|
||||
clubName = guestModel.getClub();
|
||||
}
|
||||
|
||||
return Multi.createFrom().iterable(map.entrySet())
|
||||
.onItem().call(entry -> Mutiny.fetch(entry.getKey().getTree()))
|
||||
.map(entry -> {
|
||||
ResultCategoryData tmp = new ResultCategoryData();
|
||||
if (clubName != null && !clubName.isBlank()
|
||||
&& !clubName.equals("Team") && clubMap.containsKey(clubName)) {
|
||||
ClubClassement entity = clubMap.get(clubName);
|
||||
entity.score[classementData.rank() - 1]++;
|
||||
entity.tt_score += 4 - classementData.rank();
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
getArray2(entry.getValue().stream().map(m -> new MatchModelExtend(m, cards))
|
||||
.toList(),
|
||||
null, tmp);
|
||||
getClassementArray(entry.getKey(), null, cards, tmp);
|
||||
|
||||
return tmp;
|
||||
})
|
||||
.collect().asList();
|
||||
})
|
||||
.map(categoryData -> {
|
||||
HashMap<String, ClubClassement> clubMap = new HashMap<>();
|
||||
|
||||
categoryData.forEach(
|
||||
c -> c.getClassement().stream().map(ResultCategoryData.ClassementData::comb)
|
||||
.filter(Objects::nonNull)
|
||||
.distinct()
|
||||
.map(comb -> {
|
||||
if (comb instanceof MembreModel membreModel2) {
|
||||
return (membreModel2.getClub() != null) ? membreModel2.getClub()
|
||||
.getName() : "";
|
||||
} else if (comb instanceof CompetitionGuestModel guestModel) {
|
||||
return guestModel.getClub();
|
||||
}
|
||||
return "";
|
||||
})
|
||||
.filter(s -> s != null && !s.isBlank() && !s.equals("Team"))
|
||||
.distinct()
|
||||
.forEach(clubName -> clubMap.putIfAbsent(clubName,
|
||||
new ClubClassement(clubName))));
|
||||
|
||||
categoryData.forEach(c -> c.getClassement().forEach(classementData -> {
|
||||
if (classementData.rank() > 3)
|
||||
return;
|
||||
|
||||
if (classementData.comb() != null) {
|
||||
String clubName = "";
|
||||
if (classementData.comb() instanceof MembreModel membreModel2) {
|
||||
clubName = (membreModel2.getClub() != null) ? membreModel2.getClub()
|
||||
.getName() : "";
|
||||
} else if (classementData.comb() instanceof CompetitionGuestModel guestModel) {
|
||||
clubName = guestModel.getClub();
|
||||
}
|
||||
|
||||
if (clubName != null && !clubName.isBlank()
|
||||
&& !clubName.equals("Team") && clubMap.containsKey(clubName)) {
|
||||
ClubClassement entity = clubMap.get(clubName);
|
||||
entity.score[classementData.rank() - 1]++;
|
||||
entity.tt_score += 4 - classementData.rank();
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
return clubMap.values().stream()
|
||||
.sorted(Comparator.comparingInt((ClubClassement c) -> c.tt_score)
|
||||
.thenComparingInt(c -> c.score[0])
|
||||
.thenComparingInt(c -> c.score[1])
|
||||
.thenComparingInt(c -> c.score[2]).reversed())
|
||||
.toList();
|
||||
})
|
||||
.map(l -> new Pair<>(System.currentTimeMillis() + 60 * 1000L, l))
|
||||
).map(Pair::getValue));
|
||||
return clubMap.values().stream()
|
||||
.sorted(Comparator.comparingInt((ClubClassement c) -> c.tt_score)
|
||||
.thenComparingInt(c -> c.score[0])
|
||||
.thenComparingInt(c -> c.score[1])
|
||||
.thenComparingInt(c -> c.score[2]).reversed())
|
||||
.toList();
|
||||
})
|
||||
.invoke(__ -> cacheClubClassementExp.put(uuid, System.currentTimeMillis() + 60 * 1000L))
|
||||
));
|
||||
}
|
||||
|
||||
@Data
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user