From a19aa7636962edbbf1efc04adf1159483569fe8e Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sat, 4 May 2019 18:18:50 +0700 Subject: [PATCH] Add caching --- source/net/filebot/web/ThumbnailProvider.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/source/net/filebot/web/ThumbnailProvider.java b/source/net/filebot/web/ThumbnailProvider.java index 9bbf06d5..723d9be8 100644 --- a/source/net/filebot/web/ThumbnailProvider.java +++ b/source/net/filebot/web/ThumbnailProvider.java @@ -23,24 +23,26 @@ public enum ThumbnailProvider { byte[][] response = new byte[ids.length][]; // check cache - for (int i = 0; i < request.length; i++) { + for (int i = 0; i < response.length; i++) { response[i] = (byte[]) cache.get(ids[i]); } - for (int i = 0; i < request.length; i++) { + for (int i = 0; i < response.length; i++) { if (response[i] == null) { HttpRequest r = HttpRequest.newBuilder(getThumbnailURL(ids[i])).build(); request[i] = http.sendAsync(r, BodyHandlers.ofByteArray()); } } - for (int i = 0; i < request.length; i++) { - if (response[i] == null) { + for (int i = 0; i < response.length; i++) { + if (request[i] != null) { HttpResponse r = request[i].get(); if (r.statusCode() == 200) { response[i] = r.body(); - cache.put(ids[i], response[i]); + } else { + response[i] = new byte[0]; } + cache.put(ids[i], response[i]); } }