Merge pull request 'fix: cache refresh' (#122) from dev into master
Reviewed-on: #122
This commit is contained in:
commit
a1e5006e95
@ -755,94 +755,87 @@ public class ResultService {
|
|||||||
List<CardModel> cards = new java.util.ArrayList<>();
|
List<CardModel> cards = new java.util.ArrayList<>();
|
||||||
|
|
||||||
//noinspection unchecked
|
//noinspection unchecked
|
||||||
cacheClubClassement.invalidateIf(
|
return cacheClubClassement.invalidateIf(
|
||||||
(p) -> ((Pair<Long, List<ClubClassement>>) p).getKey() > System.currentTimeMillis());
|
(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);
|
||||||
|
}
|
||||||
|
|
||||||
if (!cache)
|
return Multi.createFrom().iterable(map.entrySet())
|
||||||
cacheClubClassement.invalidate(uuid);
|
.onItem().call(entry -> Mutiny.fetch(entry.getKey().getTree()))
|
||||||
|
.map(entry -> {
|
||||||
|
ResultCategoryData tmp = new ResultCategoryData();
|
||||||
|
|
||||||
return cacheClubClassement.getAsync(uuid, k -> cardRepository.list("competition.uuid = ?1", uuid)
|
getArray2(entry.getValue().stream().map(m -> new MatchModelExtend(m, cards))
|
||||||
.invoke(__ -> System.out.println("Cache miss for club classement with uuid " + uuid))
|
.toList(),
|
||||||
.invoke(cards::addAll)
|
null, tmp);
|
||||||
.chain(__ -> matchRepository.list("category.compet.uuid = ?1", uuid))
|
getClassementArray(entry.getKey(), null, cards, tmp);
|
||||||
.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())
|
return tmp;
|
||||||
.onItem().call(entry -> Mutiny.fetch(entry.getKey().getTree()))
|
})
|
||||||
.map(entry -> {
|
.collect().asList();
|
||||||
ResultCategoryData tmp = new ResultCategoryData();
|
})
|
||||||
|
.map(categoryData -> {
|
||||||
|
HashMap<String, ClubClassement> clubMap = new HashMap<>();
|
||||||
|
|
||||||
getArray2(entry.getValue().stream().map(m -> new MatchModelExtend(m, cards)).toList(),
|
categoryData.forEach(
|
||||||
null, tmp);
|
c -> c.getClassement().stream().map(ResultCategoryData.ClassementData::comb)
|
||||||
getClassementArray(entry.getKey(), null, cards, tmp);
|
.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))));
|
||||||
|
|
||||||
return tmp;
|
categoryData.forEach(c -> c.getClassement().forEach(classementData -> {
|
||||||
})
|
if (classementData.rank() > 3)
|
||||||
.collect().asList();
|
return;
|
||||||
})
|
|
||||||
.map(categoryData -> {
|
|
||||||
HashMap<String, ClubClassement> clubMap = new HashMap<>();
|
|
||||||
|
|
||||||
categoryData.forEach(c -> c.getClassement().stream().map(ResultCategoryData.ClassementData::comb)
|
if (classementData.comb() != null) {
|
||||||
.filter(Objects::nonNull)
|
String clubName = "";
|
||||||
.distinct()
|
if (classementData.comb() instanceof MembreModel membreModel2) {
|
||||||
.map(comb -> {
|
clubName = (membreModel2.getClub() != null) ? membreModel2.getClub()
|
||||||
if (comb instanceof MembreModel membreModel2) {
|
.getName() : "";
|
||||||
return (membreModel2.getClub() != null) ? membreModel2.getClub().getName() : "";
|
} else if (classementData.comb() instanceof CompetitionGuestModel guestModel) {
|
||||||
} else if (comb instanceof CompetitionGuestModel guestModel) {
|
clubName = guestModel.getClub();
|
||||||
return 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 "";
|
}));
|
||||||
})
|
|
||||||
.filter(s -> s != null && !s.isBlank() && !s.equals("Team"))
|
|
||||||
.distinct()
|
|
||||||
.forEach(clubName -> clubMap.putIfAbsent(clubName, new ClubClassement(clubName))));
|
|
||||||
|
|
||||||
System.out.println(clubMap.keySet());
|
return clubMap.values().stream()
|
||||||
|
.sorted(Comparator.comparingInt((ClubClassement c) -> c.tt_score)
|
||||||
categoryData.forEach(c -> c.getClassement().forEach(classementData -> {
|
.thenComparingInt(c -> c.score[0])
|
||||||
System.out.println("Classement data for " + c.getName() + ": " + classementData.name() + " - " +
|
.thenComparingInt(c -> c.score[1])
|
||||||
classementData.comb() + " - " + classementData.rank());
|
.thenComparingInt(c -> c.score[2]).reversed())
|
||||||
if (classementData.rank() > 3)
|
.toList();
|
||||||
return;
|
})
|
||||||
|
.map(l -> new Pair<>(System.currentTimeMillis() + 60 * 1000L, l))
|
||||||
System.out.println(
|
).map(Pair::getValue));
|
||||||
"Processing classement data for " + c.getName() + ": " + classementData.name());
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
System.out.println("-> " + clubName + "- " + (clubName != null && !clubName.isBlank()
|
|
||||||
&& !clubName.equals("Team") && clubMap.containsKey(clubName)));
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user