Use partial cdsi request only for a maximum of 3 numbers

Fixes #1239
This commit is contained in:
AsamK 2023-10-16 17:34:28 +02:00
parent 24069c8277
commit 505de39d2a
2 changed files with 15 additions and 2 deletions

View file

@ -29,6 +29,7 @@ public class ServiceConfig {
public final static long AVATAR_DOWNLOAD_FAILSAFE_MAX_SIZE = 10 * 1024 * 1024;
public final static boolean AUTOMATIC_NETWORK_RETRY = true;
public final static int GROUP_MAX_SIZE = 1001;
public final static int MAXIMUM_ONE_OFF_REQUEST_SIZE = 3;
private final static KeyStore iasKeyStore;

View file

@ -26,6 +26,8 @@ import java.util.Map;
import java.util.Optional;
import java.util.Set;
import static org.asamk.signal.manager.config.ServiceConfig.MAXIMUM_ONE_OFF_REQUEST_SIZE;
public class RecipientHelper {
private final static Logger logger = LoggerFactory.getLogger(RecipientHelper.class);
@ -134,8 +136,15 @@ public class RecipientHelper {
public Map<String, RegisteredUser> getRegisteredUsers(
final Set<String> numbers
) throws IOException {
if (numbers.size() > MAXIMUM_ONE_OFF_REQUEST_SIZE) {
final var allNumbers = new HashSet<>(account.getRecipientStore().getAllNumbers()) {{
addAll(numbers);
}};
return getRegisteredUsers(allNumbers, false);
} else {
return getRegisteredUsers(numbers, true);
}
}
private Map<String, RegisteredUser> getRegisteredUsers(
final Set<String> numbers, final boolean isPartialRefresh
@ -174,7 +183,10 @@ public class RecipientHelper {
logger.debug("No new numbers to query.");
return Map.of();
}
logger.trace("Querying CDSI for {} new numbers ({} previous)", newNumbers.size(), previousNumbers.size());
logger.trace("Querying CDSI for {} new numbers ({} previous), isPartialRefresh={}",
newNumbers.size(),
previousNumbers.size(),
isPartialRefresh);
final var token = previousNumbers.isEmpty()
? Optional.<byte[]>empty()
: Optional.ofNullable(account.getCdsiToken());