kopia lustrzana https://github.com/ryukoposting/Signal-Android
Improve performance of GV2 profile fetch and mentions initialization.
rodzic
c0db88960c
commit
12e6ebb4df
|
@ -1,13 +1,9 @@
|
|||
package org.thoughtcrime.securesms.conversation.ui.mentions;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.WorkerThread;
|
||||
|
||||
import com.annimon.stream.Stream;
|
||||
|
||||
import org.thoughtcrime.securesms.database.GroupDatabase;
|
||||
import org.thoughtcrime.securesms.database.RecipientDatabase;
|
||||
import org.thoughtcrime.securesms.database.SignalDatabase;
|
||||
|
@ -22,7 +18,7 @@ final class MentionsPickerRepository {
|
|||
private final RecipientDatabase recipientDatabase;
|
||||
private final GroupDatabase groupDatabase;
|
||||
|
||||
MentionsPickerRepository(@NonNull Context context) {
|
||||
MentionsPickerRepository() {
|
||||
recipientDatabase = SignalDatabase.recipients();
|
||||
groupDatabase = SignalDatabase.groups();
|
||||
}
|
||||
|
@ -33,9 +29,7 @@ final class MentionsPickerRepository {
|
|||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return Stream.of(groupDatabase.getGroupMembers(recipient.requireGroupId(), GroupDatabase.MemberSet.FULL_MEMBERS_EXCLUDING_SELF))
|
||||
.map(Recipient::getId)
|
||||
.toList();
|
||||
return groupDatabase.getGroupMemberIds(recipient.requireGroupId(), GroupDatabase.MemberSet.FULL_MEMBERS_EXCLUDING_SELF);
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
|
|
|
@ -11,7 +11,6 @@ import androidx.lifecycle.ViewModelProvider;
|
|||
import com.annimon.stream.Stream;
|
||||
|
||||
import org.thoughtcrime.securesms.conversation.ui.mentions.MentionsPickerRepository.MentionQuery;
|
||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
||||
import org.thoughtcrime.securesms.recipients.LiveRecipient;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientId;
|
||||
|
@ -112,7 +111,7 @@ public class MentionsPickerViewModel extends ViewModel {
|
|||
@Override
|
||||
public @NonNull <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
|
||||
//noinspection ConstantConditions
|
||||
return modelClass.cast(new MentionsPickerViewModel(new MentionsPickerRepository(ApplicationDependencies.getApplication())));
|
||||
return modelClass.cast(new MentionsPickerViewModel(new MentionsPickerRepository()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -432,6 +432,22 @@ public class GroupDatabase extends Database {
|
|||
return 0;
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
public @NonNull List<RecipientId> getGroupMemberIds(@NonNull GroupId groupId, @NonNull MemberSet memberSet) {
|
||||
if (groupId.isV2()) {
|
||||
return getGroup(groupId).map(g -> g.requireV2GroupProperties().getMemberRecipientIds(memberSet))
|
||||
.orElse(Collections.emptyList());
|
||||
} else {
|
||||
List<RecipientId> currentMembers = getCurrentMembers(groupId);
|
||||
|
||||
if (!memberSet.includeSelf) {
|
||||
currentMembers.remove(Recipient.self().getId());
|
||||
}
|
||||
|
||||
return currentMembers;
|
||||
}
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
public @NonNull List<Recipient> getGroupMembers(@NonNull GroupId groupId, @NonNull MemberSet memberSet) {
|
||||
if (groupId.isV2()) {
|
||||
|
|
|
@ -84,7 +84,7 @@ public class RetrieveProfileJob extends BaseJob {
|
|||
* Identical to {@link #enqueue(Set)})}, but run on a background thread for convenience.
|
||||
*/
|
||||
public static void enqueueAsync(@NonNull RecipientId recipientId) {
|
||||
SignalExecutors.BOUNDED.execute(() -> ApplicationDependencies.getJobManager().add(forRecipient(recipientId)));
|
||||
SignalExecutors.BOUNDED_IO.execute(() -> ApplicationDependencies.getJobManager().add(forRecipient(recipientId)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -121,10 +121,9 @@ public class RetrieveProfileJob extends BaseJob {
|
|||
if (recipient.isSelf()) {
|
||||
return new RefreshOwnProfileJob();
|
||||
} else if (recipient.isGroup()) {
|
||||
Context context = ApplicationDependencies.getApplication();
|
||||
List<Recipient> recipients = SignalDatabase.groups().getGroupMembers(recipient.requireGroupId(), GroupDatabase.MemberSet.FULL_MEMBERS_EXCLUDING_SELF);
|
||||
List<RecipientId> recipients = SignalDatabase.groups().getGroupMemberIds(recipient.requireGroupId(), GroupDatabase.MemberSet.FULL_MEMBERS_EXCLUDING_SELF);
|
||||
|
||||
return new RetrieveProfileJob(Stream.of(recipients).map(Recipient::getId).collect(Collectors.toSet()));
|
||||
return new RetrieveProfileJob(new HashSet<>(recipients));
|
||||
} else {
|
||||
return new RetrieveProfileJob(Collections.singleton(recipientId));
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue