Yet another attempt to optimize the online accounts import queue processing.

The main difference here is that we now remove items from the onlineAccountsImportQueue in a batch, _after_ they have been imported. This prevents duplicates from being added to the queue in the previous time gap between them being removed and imported.
This commit is contained in:
CalDescent 2022-09-25 12:26:00 +01:00
parent 5989473c8a
commit 765416db71

View File

@ -207,13 +207,20 @@ public class OnlineAccountsManager {
boolean isValid = this.isValidCurrentAccount(repository, onlineAccountData);
if (isValid)
addAccounts(Arrays.asList(onlineAccountData));
onlineAccountsToAdd.add(onlineAccountData);
// Remove from queue
onlineAccountsImportQueue.remove(onlineAccountData);
// Don't remove from the queue yet - we'll do this at the end of the process
// This prevents duplicates being added to the queue whilst it's being processed
}
} catch (DataException e) {
LOGGER.error("Repository issue while verifying online accounts", e);
} finally {
if (!onlineAccountsToAdd.isEmpty()) {
LOGGER.debug("Merging {} validated online accounts from import queue", onlineAccountsToAdd.size());
addAccounts(onlineAccountsToAdd);
onlineAccountsImportQueue.removeAll(onlineAccountsToAdd);
}
}
}