forked from j62/ctbrec
1
0
Fork 0

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.
This commit is contained in:
0xboobface 2018-11-28 16:45:42 +01:00
parent ef9566999a
commit cbb6f3f45a
2 changed files with 16 additions and 5 deletions

View File

@ -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 {

View File

@ -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