Improve filter updates

Filter matches are now updated as soon, as the stream resolution has
been determined for a model
This commit is contained in:
0xboobface 2020-03-19 15:21:57 +01:00
parent 243d2757b0
commit ad06218b78
2 changed files with 8 additions and 4 deletions

View File

@ -96,7 +96,7 @@ public class ThumbCell extends StackPane {
private boolean mouseHovering = false;
private boolean recording = false;
private static ExecutorService imageLoadingThreadPool = Executors.newFixedThreadPool(30);
private static LoadingCache<Model, int[]> resolutionCache = CacheBuilder.newBuilder()
static LoadingCache<Model, int[]> resolutionCache = CacheBuilder.newBuilder()
.expireAfterAccess(5, TimeUnit.MINUTES)
.maximumSize(10000)
.build(CacheLoader.from(ThumbCell::getStreamResolution));
@ -309,6 +309,7 @@ public class ThumbCell extends StackPane {
final String text = tagText;
final Paint c = resolutionBackgroundColor;
Platform.runLater(() -> {
String oldText = resolutionTag.getText();
resolutionTag.setText(text);
if (!mouseHovering) {
resolutionTag.setVisible(true);
@ -316,6 +317,9 @@ public class ThumbCell extends StackPane {
}
resolutionBackground.setWidth(resolutionTag.getBoundsInLocal().getWidth() + 4);
resolutionBackground.setFill(c);
if (!Objects.equals(oldText, text)) {
parent.filter();
}
});
});
}

View File

@ -101,7 +101,7 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener {
List<ThumbCell> filteredThumbCells = Collections.synchronizedList(new ArrayList<>());
Recorder recorder;
String filter;
private String filter;
ReentrantLock gridLock = new ReentrantLock();
ScrollPane scrollPane = new ScrollPane();
boolean loginRequired;
@ -711,7 +711,7 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener {
alert.showAndWait();
}
private void filter() {
void filter() {
Collections.sort(filteredThumbCells, (o1, o2) -> {
ThumbCell c1 = o1;
ThumbCell c2 = o2;
@ -794,7 +794,7 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener {
}
private boolean modelPropertiesMatchToken(String token, Model m) throws IOException, ExecutionException {
int[] resolution = Optional.ofNullable(m.getStreamResolution(true)).orElse(new int[2]);
int[] resolution = Optional.ofNullable(ThumbCell.resolutionCache.getIfPresent(m)).orElse(new int[2]);
String searchText = createSearchText(m);
boolean tokensMissing = false;
if (token.matches(">\\d+")) {