From 8a4c599d9edd896b346caa8edd4d01e2090d7f84 Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 10 Mar 2019 08:08:33 +0000 Subject: [PATCH] Cache organization names --- app/src/main/java/eu/faircode/email/Helper.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/src/main/java/eu/faircode/email/Helper.java b/app/src/main/java/eu/faircode/email/Helper.java index e620da7d71..373f9fc82b 100644 --- a/app/src/main/java/eu/faircode/email/Helper.java +++ b/app/src/main/java/eu/faircode/email/Helper.java @@ -84,6 +84,7 @@ import java.text.DecimalFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; +import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -108,6 +109,8 @@ import static android.os.Process.THREAD_PRIORITY_BACKGROUND; import static androidx.browser.customtabs.CustomTabsService.ACTION_CUSTOM_TABS_CONNECTION; public class Helper { + private static Map hostOrganization = new HashMap<>(); + static final int NOTIFICATION_SYNCHRONIZE = 1; static final int NOTIFICATION_SEND = 2; static final int NOTIFICATION_EXTERNAL = 3; @@ -1018,6 +1021,10 @@ public class Helper { } static String getOrganization(String host) throws IOException { + synchronized (hostOrganization) { + if (hostOrganization.containsKey(host)) + return hostOrganization.get(host); + } InetAddress address = InetAddress.getByName(host); URL url = new URL("https://ipinfo.io/" + address.getHostAddress() + "/org"); HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(); @@ -1028,6 +1035,9 @@ public class Helper { String organization = reader.readLine(); if ("undefined".equals(organization)) organization = null; + synchronized (hostOrganization) { + hostOrganization.put(host, organization); + } return organization; } }