kopia lustrzana https://github.com/ryukoposting/Signal-Android
Break storage reads into pages of 1000.
rodzic
c09c6587b9
commit
83ee4c0147
|
@ -92,6 +92,7 @@ import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -116,12 +117,15 @@ public class SignalServiceAccountManager {
|
||||||
|
|
||||||
private static final String TAG = SignalServiceAccountManager.class.getSimpleName();
|
private static final String TAG = SignalServiceAccountManager.class.getSimpleName();
|
||||||
|
|
||||||
|
private static final int STORAGE_READ_MAX_ITEMS = 1000;
|
||||||
|
|
||||||
private final PushServiceSocket pushServiceSocket;
|
private final PushServiceSocket pushServiceSocket;
|
||||||
private final CredentialsProvider credentials;
|
private final CredentialsProvider credentials;
|
||||||
private final String userAgent;
|
private final String userAgent;
|
||||||
private final GroupsV2Operations groupsV2Operations;
|
private final GroupsV2Operations groupsV2Operations;
|
||||||
private final SignalServiceConfiguration configuration;
|
private final SignalServiceConfiguration configuration;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a SignalServiceAccountManager.
|
* Construct a SignalServiceAccountManager.
|
||||||
* @param configuration The URL for the Signal Service.
|
* @param configuration The URL for the Signal Service.
|
||||||
|
@ -566,29 +570,45 @@ public class SignalServiceAccountManager {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
List<SignalStorageRecord> result = new ArrayList<>();
|
List<SignalStorageRecord> result = new ArrayList<>();
|
||||||
ReadOperation.Builder operation = ReadOperation.newBuilder();
|
Map<ByteString, Integer> typeMap = new HashMap<>();
|
||||||
Map<ByteString, Integer> typeMap = new HashMap<>();
|
List<ReadOperation> readOperations = new LinkedList<>();
|
||||||
|
ReadOperation.Builder currentOperation = ReadOperation.newBuilder();
|
||||||
|
|
||||||
for (StorageId key : storageKeys) {
|
for (StorageId key : storageKeys) {
|
||||||
typeMap.put(ByteString.copyFrom(key.getRaw()), key.getType());
|
typeMap.put(ByteString.copyFrom(key.getRaw()), key.getType());
|
||||||
|
|
||||||
|
if (currentOperation.getReadKeyCount() >= STORAGE_READ_MAX_ITEMS) {
|
||||||
|
Log.i(TAG, "Going over max read items. Starting a new read operation.");
|
||||||
|
readOperations.add(currentOperation.build());
|
||||||
|
currentOperation = ReadOperation.newBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
if (StorageId.isKnownType(key.getType())) {
|
if (StorageId.isKnownType(key.getType())) {
|
||||||
operation.addReadKey(ByteString.copyFrom(key.getRaw()));
|
currentOperation.addReadKey(ByteString.copyFrom(key.getRaw()));
|
||||||
} else {
|
} else {
|
||||||
result.add(SignalStorageRecord.forUnknown(key));
|
result.add(SignalStorageRecord.forUnknown(key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String authToken = this.pushServiceSocket.getStorageAuth();
|
if (currentOperation.getReadKeyCount() > 0) {
|
||||||
StorageItems items = this.pushServiceSocket.readStorageItems(authToken, operation.build());
|
readOperations.add(currentOperation.build());
|
||||||
|
}
|
||||||
|
|
||||||
for (StorageItem item : items.getItemsList()) {
|
Log.i(TAG, "Reading " + storageKeys.size() + " items split over " + readOperations.size() + " page(s).");
|
||||||
Integer type = typeMap.get(item.getKey());
|
|
||||||
if (type != null) {
|
String authToken = this.pushServiceSocket.getStorageAuth();
|
||||||
result.add(SignalStorageModels.remoteToLocalStorageRecord(item, type, storageKey));
|
|
||||||
} else {
|
for (ReadOperation readOperation : readOperations) {
|
||||||
Log.w(TAG, "No type found! Skipping.");
|
StorageItems items = this.pushServiceSocket.readStorageItems(authToken, readOperation);
|
||||||
|
|
||||||
|
for (StorageItem item : items.getItemsList()) {
|
||||||
|
Integer type = typeMap.get(item.getKey());
|
||||||
|
if (type != null) {
|
||||||
|
result.add(SignalStorageModels.remoteToLocalStorageRecord(item, type, storageKey));
|
||||||
|
} else {
|
||||||
|
Log.w(TAG, "No type found! Skipping.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue