forked from j62/ctbrec
1
0
Fork 0

Use model url for key in resolution cache

This commit is contained in:
0xboobface 2019-12-29 15:06:17 +01:00
parent 16dfc07a8e
commit 702de3b772
1 changed files with 7 additions and 8 deletions

View File

@ -88,7 +88,7 @@ public class ThumbCell extends StackPane {
private boolean mouseHovering = false; private boolean mouseHovering = false;
private boolean recording = false; private boolean recording = false;
private static ExecutorService imageLoadingThreadPool = Executors.newFixedThreadPool(30); private static ExecutorService imageLoadingThreadPool = Executors.newFixedThreadPool(30);
private static Cache<Model, int[]> resolutionCache = CacheBuilder.newBuilder() private static Cache<String, int[]> resolutionCache = CacheBuilder.newBuilder()
.expireAfterAccess(4, TimeUnit.HOURS) .expireAfterAccess(4, TimeUnit.HOURS)
.maximumSize(1000) .maximumSize(1000)
.build(); .build();
@ -277,7 +277,7 @@ public class ThumbCell extends StackPane {
return; return;
} }
int[] resolution = resolutionCache.getIfPresent(model); int[] resolution = resolutionCache.getIfPresent(model.getUrl());
if (resolution != null) { if (resolution != null) {
ThumbOverviewTab.threadPool.submit(() -> { ThumbOverviewTab.threadPool.submit(() -> {
try { try {
@ -291,7 +291,7 @@ public class ThumbCell extends StackPane {
try { try {
ThumbOverviewTab.resolutionProcessing.add(model); ThumbOverviewTab.resolutionProcessing.add(model);
int[] _resolution = model.getStreamResolution(false); int[] _resolution = model.getStreamResolution(false);
resolutionCache.put(model, _resolution); resolutionCache.put(model.getUrl(), _resolution);
updateResolutionTag(_resolution); updateResolutionTag(_resolution);
// the model is online, but the resolution is 0. probably something went wrong // the model is online, but the resolution is 0. probably something went wrong
@ -324,22 +324,21 @@ public class ThumbCell extends StackPane {
} }
private void updateResolutionTag(int[] resolution) throws IOException, ExecutionException, InterruptedException { private void updateResolutionTag(int[] resolution) throws IOException, ExecutionException, InterruptedException {
String _res = "n/a";
Paint resolutionBackgroundColor = resolutionOnlineColor; Paint resolutionBackgroundColor = resolutionOnlineColor;
String state = model.getOnlineState(false).toString(); String state = model.getOnlineState(false).toString();
final String tagText;
if (model.isOnline()) { if (model.isOnline()) {
LOG.trace("Model resolution {} {}x{}", model.getName(), resolution[0], resolution[1]); LOG.trace("Model resolution {} {}x{}", model.getName(), resolution[0], resolution[1]);
LOG.trace("Resolution queue size: {}", ThumbOverviewTab.queue.size()); LOG.trace("Resolution queue size: {}", ThumbOverviewTab.queue.size());
final int w = resolution[1]; final int w = resolution[1];
_res = w > 0 ? w != Integer.MAX_VALUE ? Integer.toString(w) : "HD" : state; tagText = w > 0 ? w != Integer.MAX_VALUE ? Integer.toString(w) : "HD" : state;
} else { } else {
_res = model.getOnlineState(false).toString(); tagText = state;
resolutionBackgroundColor = resolutionOfflineColor; resolutionBackgroundColor = resolutionOfflineColor;
} }
final String resText = _res;
final Paint c = resolutionBackgroundColor; final Paint c = resolutionBackgroundColor;
Platform.runLater(() -> { Platform.runLater(() -> {
resolutionTag.setText(resText); resolutionTag.setText(tagText);
if(!mouseHovering) { if(!mouseHovering) {
resolutionTag.setVisible(true); resolutionTag.setVisible(true);
resolutionBackground.setVisible(true); resolutionBackground.setVisible(true);