From cbb6f3f45a9709ee9a0dd4b7816185eff0ceb922 Mon Sep 17 00:00:00 2001 From: 0xboobface <0xboobface@gmail.com> Date: Wed, 28 Nov 2018 16:45:42 +0100 Subject: [PATCH] Add failFast version of getStreamInfo for faster startup With many chaturbate models, the loading of the recording tab took a long time, because for each model the online state was loaded by the loading cache. The failFast version just returns null and makes the inital loading of recorder.getOnlineModels() much faster. --- .../main/java/ctbrec/sites/chaturbate/Chaturbate.java | 10 +++++++++- .../java/ctbrec/sites/chaturbate/ChaturbateModel.java | 11 +++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/common/src/main/java/ctbrec/sites/chaturbate/Chaturbate.java b/common/src/main/java/ctbrec/sites/chaturbate/Chaturbate.java index 36125f85..534a39bb 100644 --- a/common/src/main/java/ctbrec/sites/chaturbate/Chaturbate.java +++ b/common/src/main/java/ctbrec/sites/chaturbate/Chaturbate.java @@ -219,7 +219,15 @@ public class Chaturbate extends AbstractSite { } StreamInfo getStreamInfo(String modelName) throws IOException, ExecutionException { - return streamInfoCache.get(modelName); + return getStreamInfo(modelName, false); + } + + StreamInfo getStreamInfo(String modelName, boolean failFast) throws IOException, ExecutionException { + if(failFast) { + return streamInfoCache.getIfPresent(modelName); + } else { + return streamInfoCache.get(modelName); + } } StreamInfo loadStreamInfo(String modelName) throws HttpException, IOException, InterruptedException { diff --git a/common/src/main/java/ctbrec/sites/chaturbate/ChaturbateModel.java b/common/src/main/java/ctbrec/sites/chaturbate/ChaturbateModel.java index 3095c4be..bd17cd23 100644 --- a/common/src/main/java/ctbrec/sites/chaturbate/ChaturbateModel.java +++ b/common/src/main/java/ctbrec/sites/chaturbate/ChaturbateModel.java @@ -6,6 +6,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Objects; +import java.util.Optional; import java.util.concurrent.ExecutionException; import org.slf4j.Logger; @@ -39,14 +40,16 @@ public class ChaturbateModel extends AbstractModel { @Override public boolean isOnline(boolean ignoreCache) throws IOException, ExecutionException, InterruptedException { - StreamInfo info; + String roomStatus; if(ignoreCache) { - info = getChaturbate().loadStreamInfo(getName()); + StreamInfo info = getChaturbate().loadStreamInfo(getName()); + roomStatus = Optional.ofNullable(info).map(i -> i.room_status).orElse(""); LOG.trace("Model {} room status: {}", getName(), info.room_status); } else { - info = getChaturbate().getStreamInfo(getName()); + StreamInfo info = getChaturbate().getStreamInfo(getName(), true); + roomStatus = Optional.ofNullable(info).map(i -> i.room_status).orElse(""); } - return Objects.equals("public", info.room_status); + return Objects.equals("public", roomStatus); } @Override