Add accounts from the import queue individually, and then skip future duplicates before unnecessarily validating them again.

This closes a gap where accounts would be moved from onlineAccountsImportQueue to onlineAccountsToAdd, but not yet imported. During this time, there was nothing to stop them from being added to the import queue again, causing duplicate validations.
This commit is contained in:
CalDescent 2022-09-24 10:56:52 +01:00
parent c7cf33ef78
commit 174a779e4c

View File

@ -193,9 +193,17 @@ public class OnlineAccountsManager {
if (isStopping)
return;
// Skip this account if it's already validated
Set<OnlineAccountData> onlineAccounts = this.currentOnlineAccounts.computeIfAbsent(onlineAccountData.getTimestamp(), k -> ConcurrentHashMap.newKeySet());
if (onlineAccounts.contains(onlineAccountData)) {
// We have already validated this online account
onlineAccountsImportQueue.remove(onlineAccountData);
continue;
}
boolean isValid = this.isValidCurrentAccount(repository, onlineAccountData);
if (isValid)
onlineAccountsToAdd.add(onlineAccountData);
addAccounts(Arrays.asList(onlineAccountData));
// Remove from queue
onlineAccountsImportQueue.remove(onlineAccountData);
@ -203,11 +211,6 @@ public class OnlineAccountsManager {
} catch (DataException e) {
LOGGER.error("Repository issue while verifying online accounts", e);
}
if (!onlineAccountsToAdd.isEmpty()) {
LOGGER.debug("Merging {} validated online accounts from import queue", onlineAccountsToAdd.size());
addAccounts(onlineAccountsToAdd);
}
}
private boolean importQueueContainsExactMatch(OnlineAccountData acc) {
@ -381,7 +384,7 @@ public class OnlineAccountsManager {
}
}
LOGGER.debug(String.format("we have online accounts for timestamps: %s", String.join(", ", this.currentOnlineAccounts.keySet().stream().map(l -> Long.toString(l)).collect(Collectors.joining(", ")))));
LOGGER.trace(String.format("we have online accounts for timestamps: %s", String.join(", ", this.currentOnlineAccounts.keySet().stream().map(l -> Long.toString(l)).collect(Collectors.joining(", ")))));
return true;
}