diff --git a/app/src/main/java/eu/faircode/email/ContactInfo.java b/app/src/main/java/eu/faircode/email/ContactInfo.java index de20f1a0bb..569fd753e6 100644 --- a/app/src/main/java/eu/faircode/email/ContactInfo.java +++ b/app/src/main/java/eu/faircode/email/ContactInfo.java @@ -94,6 +94,7 @@ public class ContactInfo { private static Map emailLookup = new ConcurrentHashMap<>(); private static final Map emailContactInfo = new HashMap<>(); private static final Map emailGravatar = new HashMap<>(); + private static final Map> accountIdentities = new HashMap<>(); private static final ExecutorService executorLookup = Helper.getBackgroundExecutor(1, "contact"); @@ -193,6 +194,12 @@ public class ContactInfo { }); } + static void clearIdentities() { + synchronized (accountIdentities) { + accountIdentities.clear(); + } + } + @NonNull static ContactInfo[] get(Context context, long account, String folderType, Address[] addresses) { return get(context, account, folderType, addresses, false); @@ -750,7 +757,14 @@ public class ContactInfo { // Check if from self if (type == EntityContact.TYPE_FROM) { if (message.from != null) { - List identities = db.identity().getSynchronizingIdentities(folder.account); + List identities; + synchronized (accountIdentities) { + if (!accountIdentities.containsKey(folder.account)) + accountIdentities.put(folder.account, + db.identity().getSynchronizingIdentities(folder.account)); + identities = accountIdentities.get(folder.account); + } + if (identities != null) { for (Address sender : message.from) { for (EntityIdentity identity : identities) diff --git a/app/src/main/java/eu/faircode/email/FragmentIdentity.java b/app/src/main/java/eu/faircode/email/FragmentIdentity.java index 6976c4f7ef..a04a4df3a2 100644 --- a/app/src/main/java/eu/faircode/email/FragmentIdentity.java +++ b/app/src/main/java/eu/faircode/email/FragmentIdentity.java @@ -990,6 +990,8 @@ public class FragmentIdentity extends FragmentBase { db.endTransaction(); } + ContactInfo.clearIdentities(); + return false; } @@ -1374,6 +1376,8 @@ public class FragmentIdentity extends FragmentBase { DB db = DB.getInstance(context); db.identity().deleteIdentity(id); + ContactInfo.clearIdentities(); + return null; }