Introduce extra caching for group message processing.

This commit is contained in:
Clark
2023-05-17 13:54:37 -04:00
committed by Greyson Parrelli
parent 44ab1643fa
commit 2d6b16b2ce
15 changed files with 149 additions and 33 deletions

View File

@@ -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));
}
/**

View File

@@ -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.

View File

@@ -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);