From 3296b1befe1d004321f56a48107be7f865807908 Mon Sep 17 00:00:00 2001 From: Maschell Date: Tue, 30 Apr 2019 12:03:39 +0200 Subject: [PATCH] Add caching for the h3 values on remote accesses --- .../NUSDataProviderRemote.java | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/de/mas/wiiu/jnus/implementations/NUSDataProviderRemote.java b/src/de/mas/wiiu/jnus/implementations/NUSDataProviderRemote.java index 6d55bdb..a34eed8 100644 --- a/src/de/mas/wiiu/jnus/implementations/NUSDataProviderRemote.java +++ b/src/de/mas/wiiu/jnus/implementations/NUSDataProviderRemote.java @@ -18,6 +18,8 @@ package de.mas.wiiu.jnus.implementations; import java.io.IOException; import java.io.InputStream; +import java.util.HashMap; +import java.util.Map; import java.util.Optional; import de.mas.wiiu.jnus.Settings; @@ -46,16 +48,25 @@ public class NUSDataProviderRemote implements NUSDataProvider, Parallelizable { return String.format("%016x/%08X", titleID, content.getID()); } + Map> h3Hashes = new HashMap<>(); + @Override public Optional getContentH3Hash(Content content) throws IOException { - NUSDownloadService downloadService = NUSDownloadService.getDefaultInstance(); - String url = getRemoteURL(content) + Settings.H3_EXTENTION; + Optional resOpt = h3Hashes.get(content.getID()); + if (resOpt == null) { + NUSDownloadService downloadService = NUSDownloadService.getDefaultInstance(); + String url = getRemoteURL(content) + Settings.H3_EXTENTION; + System.out.println(url); - byte[] res = downloadService.downloadToByteArray(url); - if (res == null || res.length == 0) { - return Optional.empty(); + byte[] res = downloadService.downloadToByteArray(url); + if (res == null || res.length == 0) { + resOpt = Optional.empty(); + } else { + resOpt = Optional.of(res); + } + h3Hashes.put(content.getID(), resOpt); } - return Optional.of(res); + return resOpt; } @Override