mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-24 10:51:27 +01:00
Introduce extra caching for group message processing.
This commit is contained in:
@@ -336,7 +336,7 @@ public class Recipient {
|
||||
*/
|
||||
@WorkerThread
|
||||
public static @NonNull Recipient externalPossiblyMigratedGroup(@NonNull GroupId groupId) {
|
||||
return Recipient.resolved(SignalDatabase.recipients().getOrInsertFromPossiblyMigratedGroupId(groupId));
|
||||
return Recipient.resolved(RecipientId.from(groupId));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -13,6 +13,7 @@ import com.annimon.stream.Stream;
|
||||
import org.signal.core.util.DatabaseId;
|
||||
import org.signal.core.util.LongSerializer;
|
||||
import org.thoughtcrime.securesms.database.SignalDatabase;
|
||||
import org.thoughtcrime.securesms.groups.GroupId;
|
||||
import org.thoughtcrime.securesms.util.DelimiterUtil;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.whispersystems.signalservice.api.push.ServiceId;
|
||||
@@ -69,6 +70,16 @@ public class RecipientId implements Parcelable, Comparable<RecipientId>, Databas
|
||||
return from(null, identifier);
|
||||
}
|
||||
|
||||
public static @NonNull RecipientId from(@NonNull GroupId groupId) {
|
||||
RecipientId recipientId = RecipientIdCache.INSTANCE.get(groupId);
|
||||
if (recipientId == null) {
|
||||
recipientId = SignalDatabase.recipients().getOrInsertFromPossiblyMigratedGroupId(groupId);
|
||||
if (groupId.isV2()) {
|
||||
RecipientIdCache.INSTANCE.put(groupId, recipientId);
|
||||
}
|
||||
}
|
||||
return recipientId;
|
||||
}
|
||||
/**
|
||||
* Used for when you have a string that could be either a UUID or an e164. This was primarily
|
||||
* created for interacting with protocol stores.
|
||||
|
||||
@@ -4,6 +4,7 @@ import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.signal.core.util.logging.Log;
|
||||
import org.thoughtcrime.securesms.groups.GroupId;
|
||||
import org.whispersystems.signalservice.api.push.ServiceId;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -50,6 +51,14 @@ final class RecipientIdCache {
|
||||
put(recipientId, e164.orElse(null), serviceId.orElse(null));
|
||||
}
|
||||
|
||||
synchronized @Nullable RecipientId get(@NonNull GroupId groupId) {
|
||||
return ids.get(groupId);
|
||||
}
|
||||
|
||||
synchronized void put(@NonNull GroupId groupId, @NonNull RecipientId recipientId) {
|
||||
ids.put(groupId, recipientId);
|
||||
}
|
||||
|
||||
synchronized @Nullable RecipientId get(@Nullable ServiceId serviceId, @Nullable String e164) {
|
||||
if (serviceId != null && e164 != null) {
|
||||
RecipientId recipientIdByAci = ids.get(serviceId);
|
||||
|
||||
Reference in New Issue
Block a user