Skip to content
This repository has been archived by the owner on Oct 26, 2023. It is now read-only.

Use ExpiringValue to avoid successive uncached calls to getVotingResults #45

Merged
merged 2 commits into from
Oct 4, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.util.Random;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.random.RandomGenerator;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -62,6 +63,7 @@
import org.tweetwallfx.conference.spi.TrackImpl;
import org.tweetwallfx.conference.spi.util.RestCallHelper;
import org.tweetwallfx.config.Configuration;
import org.tweetwallfx.util.ExpiringValue;

public class ConferenceClientImpl implements ConferenceClient, RatingClient {
mklaehn marked this conversation as resolved.
Show resolved Hide resolved

Expand All @@ -70,6 +72,7 @@ public class ConferenceClientImpl implements ConferenceClient, RatingClient {
private final Map<String, SessionType> sessionTypes;
private final Map<String, Room> rooms;
private final Map<String, Track> tracks;
private final ExpiringValue<Map<WeekDay, List<RatedTalk>>> ratedTalks;

public ConferenceClientImpl() {
this.config = Configuration.getInstance().getConfigTyped(
Expand All @@ -93,6 +96,7 @@ public ConferenceClientImpl() {
.map(this::convertTrack)
.collect(Collectors.toMap(Identifiable::getId, Function.identity()));
LOG.info("Track IDs: {}", tracks.keySet());
this.ratedTalks = new ExpiringValue<>(this::getVotingResults, Duration.ofSeconds(20));
}

@Override
Expand Down Expand Up @@ -132,10 +136,11 @@ public List<ScheduleSlot> getSchedule(final String conferenceDay, final String r

@Override
public List<Speaker> getSpeakers() {
return RestCallHelper.readOptionalFrom(config.getEventBaseUri() + "speakers", listOfMaps(), (a, b) -> {
a.addAll(b);
return a;
})
return RestCallHelper
.readOptionalFrom(config.getEventBaseUri() + "speakers", listOfMaps(), (a, b) -> {
a.addAll(b);
return a;
})
.orElse(List.of())
.stream()
.map(this::convertSpeaker)
Expand Down Expand Up @@ -183,7 +188,7 @@ public List<RatedTalk> getRatedTalks(final String conferenceDay) {
LOG.debug("######## randomizedRatedTalksPerDay");
return randomizedRatedTalks();
} else {
final Map<WeekDay, List<RatedTalk>> votingResults = getVotingResults();
final Map<WeekDay, List<RatedTalk>> votingResults = ratedTalks.getValue();

return votingResults.entrySet().stream()
.filter(e -> e.getKey().dayId().equals(conferenceDay))
Expand All @@ -204,10 +209,10 @@ public List<RatedTalk> getRatedTalksOverall() {
LOG.debug("######## randomizedRatedTalksWeek");
return randomizedRatedTalks();
} else {
return getVotingResults().entrySet().stream()
.map(Map.Entry::getValue)
.flatMap(List::stream)
.toList();
return ratedTalks.getValue().entrySet().stream()
.map(Map.Entry::getValue)
.flatMap(List::stream)
.toList();
}
}

Expand Down
Loading