Improve cold start performance.

This commit is contained in:
Cody Henthorne
2022-07-21 12:29:58 -04:00
parent d159a0482a
commit fe6058e0df
28 changed files with 82 additions and 97 deletions

View File

@@ -152,19 +152,8 @@ public final class LiveRecipient {
Log.w(TAG, "[Resolve][MAIN] " + getId(), new Throwable());
}
Recipient updated = fetchAndCacheRecipientFromDisk(getId());
List<Recipient> participants = Stream.of(updated.getParticipants())
.filter(Recipient::isResolving)
.map(Recipient::getId)
.map(this::fetchAndCacheRecipientFromDisk)
.toList();
for (Recipient participant : participants) {
participant.live().set(participant);
}
Recipient updated = fetchAndCacheRecipientFromDisk(getId());
set(updated);
return updated;
}
@@ -188,16 +177,7 @@ public final class LiveRecipient {
Log.w(TAG, "[Refresh][MAIN] " + id, new Throwable());
}
Recipient recipient = fetchAndCacheRecipientFromDisk(id);
List<Recipient> participants = Stream.of(recipient.getParticipants())
.map(Recipient::getId)
.map(this::fetchAndCacheRecipientFromDisk)
.toList();
for (Recipient participant : participants) {
participant.live().set(participant);
}
Recipient recipient = fetchAndCacheRecipientFromDisk(id);
set(recipient);
refreshForceNotify.postValue(new Object());
}
@@ -231,9 +211,9 @@ public final class LiveRecipient {
Optional<GroupRecord> groupRecord = groupDatabase.getGroup(record.getId());
if (groupRecord.isPresent()) {
String title = groupRecord.get().getTitle();
List<Recipient> members = Stream.of(groupRecord.get().getMembers()).filterNot(RecipientId::isUnknown).map(this::fetchAndCacheRecipientFromDisk).toList();
Optional<Long> avatarId = Optional.empty();
String title = groupRecord.get().getTitle();
List<RecipientId> members = Stream.of(groupRecord.get().getMembers()).filterNot(RecipientId::isUnknown).toList();
Optional<Long> avatarId = Optional.empty();
if (groupRecord.get().hasAvatar()) {
avatarId = Optional.of(groupRecord.get().getAvatarId());
@@ -251,8 +231,8 @@ public final class LiveRecipient {
// TODO [stories] We'll have to see what the perf is like for very large distribution lists. We may not be able to support fetching all the members.
if (groupRecord != null) {
String title = groupRecord.isUnknown() ? null : groupRecord.getName();
List<Recipient> members = Stream.of(groupRecord.getMembers()).filterNot(RecipientId::isUnknown).map(this::fetchAndCacheRecipientFromDisk).toList();
String title = groupRecord.isUnknown() ? null : groupRecord.getName();
List<RecipientId> members = Stream.of(groupRecord.getMembers()).filterNot(RecipientId::isUnknown).toList();
return RecipientDetails.forDistributionList(title, members, record);
}

View File

@@ -72,6 +72,7 @@ import io.reactivex.rxjava3.schedulers.Schedulers;
import static org.thoughtcrime.securesms.database.RecipientDatabase.InsightsBannerTier;
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
public class Recipient {
private static final String TAG = Log.tag(Recipient.class);
@@ -91,7 +92,7 @@ public class Recipient {
private final String email;
private final GroupId groupId;
private final DistributionListId distributionListId;
private final List<Recipient> participants;
private final List<RecipientId> participantIds;
private final Optional<Long> groupAvatarId;
private final boolean isSelf;
private final boolean blocked;
@@ -368,7 +369,7 @@ public class Recipient {
this.email = null;
this.groupId = null;
this.distributionListId = null;
this.participants = Collections.emptyList();
this.participantIds = Collections.emptyList();
this.groupAvatarId = Optional.empty();
this.isSelf = false;
this.blocked = false;
@@ -426,7 +427,7 @@ public class Recipient {
this.email = details.email;
this.groupId = details.groupId;
this.distributionListId = details.distributionListId;
this.participants = details.participants;
this.participantIds = details.participantIds;
this.groupAvatarId = details.groupAvatarId;
this.isSelf = details.isSelf;
this.blocked = details.blocked;
@@ -488,10 +489,12 @@ public class Recipient {
public @Nullable String getGroupName(@NonNull Context context) {
if (groupId != null && Util.isEmpty(this.groupName)) {
List<Recipient> others = participants.stream()
.filter(r -> !r.isSelf())
.limit(MAX_MEMBER_NAMES)
.collect(Collectors.toList());
RecipientId selfId = Recipient.self().getId();
List<Recipient> others = participantIds.stream()
.filter(id -> !id.equals(selfId))
.limit(MAX_MEMBER_NAMES)
.map(Recipient::resolved)
.collect(Collectors.toList());
Map<String, Integer> shortNameCounts = new HashMap<>();
@@ -515,7 +518,7 @@ public class Recipient {
}
}
if (participants.stream().anyMatch(Recipient::isSelf)) {
if (participantIds.stream().anyMatch(id -> id.equals(selfId))) {
names.add(context.getString(R.string.Recipient_you));
}
@@ -861,11 +864,12 @@ public class Recipient {
}
public boolean isActiveGroup() {
return Stream.of(getParticipants()).anyMatch(Recipient::isSelf);
RecipientId selfId = Recipient.self().getId();
return Stream.of(getParticipantIds()).anyMatch(p -> p.equals(selfId));
}
public @NonNull List<Recipient> getParticipants() {
return new ArrayList<>(participants);
public @NonNull List<RecipientId> getParticipantIds() {
return new ArrayList<>(participantIds);
}
public @NonNull Drawable getFallbackContactPhotoDrawable(Context context, boolean inverted) {
@@ -1277,7 +1281,7 @@ public class Recipient {
Objects.equals(e164, other.e164) &&
Objects.equals(email, other.email) &&
Objects.equals(groupId, other.groupId) &&
allContentsAreTheSame(participants, other.participants) &&
Objects.equals(participantIds, other.participantIds) &&
Objects.equals(groupAvatarId, other.groupAvatarId) &&
messageVibrate == other.messageVibrate &&
callVibrate == other.callVibrate &&

View File

@@ -54,7 +54,7 @@ public class RecipientDetails {
final VibrateState callVibrateState;
final boolean blocked;
final int expireMessages;
final List<Recipient> participants;
final List<RecipientId> participantIds;
final ProfileName profileName;
final Optional<Integer> defaultSubscriptionId;
final RegisteredState registered;
@@ -96,7 +96,7 @@ public class RecipientDetails {
boolean isSelf,
@NonNull RegisteredState registeredState,
@NonNull RecipientRecord record,
@Nullable List<Recipient> participants,
@Nullable List<RecipientId> participantIds,
boolean isReleaseChannel)
{
this.groupAvatarId = groupAvatarId;
@@ -117,7 +117,7 @@ public class RecipientDetails {
this.callVibrateState = record.getCallVibrateState();
this.blocked = record.isBlocked();
this.expireMessages = record.getExpireMessages();
this.participants = participants == null ? new LinkedList<>() : participants;
this.participantIds = participantIds == null ? new LinkedList<>() : participantIds;
this.profileName = record.getProfileName();
this.defaultSubscriptionId = record.getDefaultSubscriptionId();
this.registered = registeredState;
@@ -174,7 +174,7 @@ public class RecipientDetails {
this.callVibrateState = VibrateState.DEFAULT;
this.blocked = false;
this.expireMessages = 0;
this.participants = new LinkedList<>();
this.participantIds = new LinkedList<>();
this.profileName = ProfileName.EMPTY;
this.insightsBannerTier = InsightsBannerTier.TIER_TWO;
this.defaultSubscriptionId = Optional.empty();
@@ -231,7 +231,7 @@ public class RecipientDetails {
return new RecipientDetails(null, settings.getSystemDisplayName(), Optional.empty(), systemContact, isSelf, registeredState, settings, null, isReleaseChannel);
}
public static @NonNull RecipientDetails forDistributionList(String title, @Nullable List<Recipient> members, @NonNull RecipientRecord record) {
public static @NonNull RecipientDetails forDistributionList(String title, @Nullable List<RecipientId> members, @NonNull RecipientRecord record) {
return new RecipientDetails(title, null, Optional.empty(), false, false, record.getRegistered(), record, members, false);
}