mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-22 01:40:07 +01:00
Reduce number of db calls to getGroup.
This commit is contained in:
@@ -18,6 +18,7 @@ import org.thoughtcrime.securesms.database.SignalDatabase;
|
||||
import org.thoughtcrime.securesms.database.model.GroupRecord;
|
||||
import org.thoughtcrime.securesms.groups.v2.GroupInviteLinkUrl;
|
||||
import org.thoughtcrime.securesms.groups.v2.GroupLinkPassword;
|
||||
import org.thoughtcrime.securesms.groups.v2.processing.GroupsV2StateProcessor;
|
||||
import org.thoughtcrime.securesms.profiles.AvatarHelper;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientId;
|
||||
@@ -178,15 +179,15 @@ public final class GroupManager {
|
||||
* processing deny messages.
|
||||
*/
|
||||
@WorkerThread
|
||||
public static void updateGroupFromServer(@NonNull Context context,
|
||||
@NonNull GroupMasterKey groupMasterKey,
|
||||
int revision,
|
||||
long timestamp,
|
||||
@Nullable byte[] signedGroupChange)
|
||||
public static GroupsV2StateProcessor.GroupUpdateResult updateGroupFromServer(@NonNull Context context,
|
||||
@NonNull GroupMasterKey groupMasterKey,
|
||||
int revision,
|
||||
long timestamp,
|
||||
@Nullable byte[] signedGroupChange)
|
||||
throws GroupChangeBusyException, IOException, GroupNotAMemberException
|
||||
{
|
||||
try (GroupManagerV2.GroupUpdater updater = new GroupManagerV2(context).updater(groupMasterKey)) {
|
||||
updater.updateLocalToServerRevision(revision, timestamp, signedGroupChange);
|
||||
return updater.updateLocalToServerRevision(revision, timestamp, signedGroupChange);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -797,11 +797,11 @@ final class GroupManagerV2 {
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
void updateLocalToServerRevision(int revision, long timestamp, @Nullable byte[] signedGroupChange)
|
||||
GroupsV2StateProcessor.GroupUpdateResult updateLocalToServerRevision(int revision, long timestamp, @Nullable byte[] signedGroupChange)
|
||||
throws IOException, GroupNotAMemberException
|
||||
{
|
||||
new GroupsV2StateProcessor(context).forGroup(serviceIds, groupMasterKey)
|
||||
.updateLocalGroupToRevision(revision, timestamp, getDecryptedGroupChange(signedGroupChange));
|
||||
return new GroupsV2StateProcessor(context).forGroup(serviceIds, groupMasterKey)
|
||||
.updateLocalGroupToRevision(revision, timestamp, getDecryptedGroupChange(signedGroupChange));
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
|
||||
@@ -133,7 +133,7 @@ public class GroupsV2StateProcessor {
|
||||
this.latestServer = latestServer;
|
||||
}
|
||||
|
||||
public GroupState getGroupState() {
|
||||
public @NonNull GroupState getGroupState() {
|
||||
return groupState;
|
||||
}
|
||||
|
||||
@@ -229,13 +229,14 @@ public class GroupsV2StateProcessor {
|
||||
@Nullable DecryptedGroupChange signedGroupChange)
|
||||
throws IOException, GroupNotAMemberException
|
||||
{
|
||||
if (localIsAtLeast(revision)) {
|
||||
Optional<GroupRecord> localRecord = groupDatabase.getGroup(groupId);
|
||||
|
||||
if (localIsAtLeast(localRecord, revision)) {
|
||||
return new GroupUpdateResult(GroupState.GROUP_CONSISTENT_OR_AHEAD, null);
|
||||
}
|
||||
|
||||
GlobalGroupState inputGroupState = null;
|
||||
|
||||
Optional<GroupRecord> localRecord = groupDatabase.getGroup(groupId);
|
||||
DecryptedGroup localState = localRecord.map(g -> g.requireV2GroupProperties().getDecryptedGroup()).orElse(null);
|
||||
|
||||
if (signedGroupChange != null &&
|
||||
@@ -540,11 +541,11 @@ public class GroupsV2StateProcessor {
|
||||
/**
|
||||
* @return true iff group exists locally and is at least the specified revision.
|
||||
*/
|
||||
private boolean localIsAtLeast(int revision) {
|
||||
if (groupDatabase.isUnknownGroup(groupId) || revision == LATEST) {
|
||||
private boolean localIsAtLeast(Optional<GroupRecord> localRecord, int revision) {
|
||||
if (revision == LATEST || localRecord.isEmpty() || groupDatabase.isUnknownGroup(localRecord)) {
|
||||
return false;
|
||||
}
|
||||
int dbRevision = groupDatabase.getGroup(groupId).get().requireV2GroupProperties().getGroupRevision();
|
||||
int dbRevision = localRecord.get().requireV2GroupProperties().getGroupRevision();
|
||||
return revision <= dbRevision;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user