parent
fa4e492d1c
commit
32c0712715
|
@ -171,12 +171,15 @@ public class DirectoryManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class TokenValue {
|
private static class TokenValue {
|
||||||
|
|
||||||
@JsonProperty(value = "r")
|
@JsonProperty(value = "r")
|
||||||
private String relay;
|
private String relay;
|
||||||
|
|
||||||
@JsonProperty(value = "s")
|
@JsonProperty(value = "s")
|
||||||
private boolean supportsSms;
|
private boolean supportsSms;
|
||||||
|
|
||||||
|
public TokenValue() {}
|
||||||
|
|
||||||
public TokenValue(String relay, boolean supportsSms) {
|
public TokenValue(String relay, boolean supportsSms) {
|
||||||
this.relay = relay;
|
this.relay = relay;
|
||||||
this.supportsSms = supportsSms;
|
this.supportsSms = supportsSms;
|
||||||
|
|
|
@ -38,6 +38,8 @@ import static org.whispersystems.textsecuregcm.storage.DirectoryManager.PendingC
|
||||||
|
|
||||||
public class DirectoryUpdater {
|
public class DirectoryUpdater {
|
||||||
|
|
||||||
|
private static final int CHUNK_SIZE = 10000;
|
||||||
|
|
||||||
private final Logger logger = LoggerFactory.getLogger(DirectoryUpdater.class);
|
private final Logger logger = LoggerFactory.getLogger(DirectoryUpdater.class);
|
||||||
|
|
||||||
private final AccountsManager accountsManager;
|
private final AccountsManager accountsManager;
|
||||||
|
@ -60,24 +62,28 @@ public class DirectoryUpdater {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
logger.info("Updating from local DB.");
|
logger.info("Updating from local DB.");
|
||||||
Iterator<Account> accounts = accountsManager.getAll();
|
int offset = 0;
|
||||||
|
|
||||||
if (accounts == null)
|
for (;;) {
|
||||||
return;
|
List<Account> accounts = accountsManager.getAll(offset, CHUNK_SIZE);
|
||||||
|
|
||||||
while (accounts.hasNext()) {
|
if (accounts == null || accounts.isEmpty()) break;
|
||||||
Account account = accounts.next();
|
else offset += accounts.size();
|
||||||
|
|
||||||
if (account.isActive()) {
|
for (Account account : accounts) {
|
||||||
byte[] token = Util.getContactToken(account.getNumber());
|
if (account.isActive()) {
|
||||||
ClientContact clientContact = new ClientContact(token, null, account.getSupportsSms());
|
byte[] token = Util.getContactToken(account.getNumber());
|
||||||
|
ClientContact clientContact = new ClientContact(token, null, account.getSupportsSms());
|
||||||
|
|
||||||
directory.add(batchOperation, clientContact);
|
directory.add(batchOperation, clientContact);
|
||||||
contactsAdded++;
|
contactsAdded++;
|
||||||
} else {
|
} else {
|
||||||
directory.remove(batchOperation, account.getNumber());
|
directory.remove(batchOperation, account.getNumber());
|
||||||
contactsRemoved++;
|
contactsRemoved++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.info("Processed " + CHUNK_SIZE + " local accounts...");
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
directory.stopBatchOperation(batchOperation);
|
directory.stopBatchOperation(batchOperation);
|
||||||
|
|
Loading…
Reference in New Issue