Use dedicated contact info executors

pull/210/head
M66B 2 years ago
parent 715b471eb0
commit f1ca83c59e

@ -75,6 +75,7 @@ import java.util.Map;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import javax.mail.Address; import javax.mail.Address;
@ -99,6 +100,8 @@ public class ContactInfo {
private static Map<String, Lookup> emailLookup = new ConcurrentHashMap<>(); private static Map<String, Lookup> emailLookup = new ConcurrentHashMap<>();
private static final Map<String, ContactInfo> emailContactInfo = new HashMap<>(); private static final Map<String, ContactInfo> emailContactInfo = new HashMap<>();
private static final ExecutorService executor = Helper.getBackgroundExecutor(0, "contact");
private static final ExecutorService favicons = Helper.getBackgroundExecutor(0, "favicons");
private static final int GENERATED_ICON_SIZE = 48; // dp private static final int GENERATED_ICON_SIZE = 48; // dp
private static final int FAVICON_ICON_SIZE = 64; // dp private static final int FAVICON_ICON_SIZE = 64; // dp
@ -374,7 +377,7 @@ public class ContactInfo {
List<Future<Favicon>> futures = new ArrayList<>(); List<Future<Favicon>> futures = new ArrayList<>();
if (bimi) if (bimi)
futures.add(Helper.getParallelExecutor().submit(new Callable<Favicon>() { futures.add(executor.submit(new Callable<Favicon>() {
@Override @Override
public Favicon call() throws Exception { public Favicon call() throws Exception {
Pair<Bitmap, Boolean> bimi = Pair<Bitmap, Boolean> bimi =
@ -384,9 +387,9 @@ public class ContactInfo {
})); }));
if (gravatars) if (gravatars)
futures.add(Helper.getParallelExecutor().submit(Avatar.getGravatar(email, scaleToPixels, context))); futures.add(executor.submit(Avatar.getGravatar(email, scaleToPixels, context)));
if (libravatars) if (libravatars)
futures.add(Helper.getParallelExecutor().submit(Avatar.getLibravatar(email, scaleToPixels, context))); futures.add(executor.submit(Avatar.getLibravatar(email, scaleToPixels, context)));
if (favicons) { if (favicons) {
String host = domain; String host = domain;
@ -395,7 +398,7 @@ public class ContactInfo {
while (host.indexOf('.') > 0) { while (host.indexOf('.') > 0) {
final URL base = new URL("https://" + host); final URL base = new URL("https://" + host);
futures.add(Helper.getParallelExecutor().submit(new Callable<Favicon>() { futures.add(executor.submit(new Callable<Favicon>() {
@Override @Override
public Favicon call() throws Exception { public Favicon call() throws Exception {
return parseFavicon(base, scaleToPixels, context); return parseFavicon(base, scaleToPixels, context);
@ -413,7 +416,7 @@ public class ContactInfo {
final URL base = new URL("https://" + host); final URL base = new URL("https://" + host);
for (String name : FIXED_FAVICONS) for (String name : FIXED_FAVICONS)
futures.add(Helper.getParallelExecutor().submit(new Callable<Favicon>() { futures.add(executor.submit(new Callable<Favicon>() {
@Override @Override
public Favicon call() throws Exception { public Favicon call() throws Exception {
return getFavicon(new URL(base, name), null, scaleToPixels, context); return getFavicon(new URL(base, name), null, scaleToPixels, context);
@ -745,7 +748,7 @@ public class ContactInfo {
continue; continue;
final URL url = new URL(base, favicon); final URL url = new URL(base, favicon);
futures.add(Helper.getParallelExecutor().submit(new Callable<Pair<Favicon, URL>>() { futures.add(favicons.submit(new Callable<Pair<Favicon, URL>>() {
@Override @Override
public Pair<Favicon, URL> call() throws Exception { public Pair<Favicon, URL> call() throws Exception {
return new Pair(getFavicon(url, img.attr("type"), scaleToPixels, context), url); return new Pair(getFavicon(url, img.attr("type"), scaleToPixels, context), url);

Loading…
Cancel
Save