From d287f5b5d0e82ea886ffa951448ae53c8296b557 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com> Date: Fri, 17 Aug 2018 13:46:02 -0400 Subject: [PATCH] manager: make getAllAccounts return accounts not in the order list Change-Id: I6ad737887943bb49d61d38a38c0fb7534fb6c564 Reviewed-by: Sebastien Blin <sebastien.blin@savoirfairelinux.com> --- src/manager.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/manager.h b/src/manager.h index dc555e1857..61e915eb47 100644 --- a/src/manager.h +++ b/src/manager.h @@ -41,6 +41,7 @@ #include <memory> #include <atomic> #include <functional> +#include <algorithm> namespace ring { @@ -765,18 +766,17 @@ class Manager { */ template <class T=Account> std::vector<std::shared_ptr<T>> getAllAccounts() const { - auto account_order = loadAccountOrder(); + const auto& account_order = loadAccountOrder(); + const auto& all_accounts = accountFactory.getAllAccounts<T>(); std::vector<std::shared_ptr<T>> accountList; - - // If no order has been set, load the default one ie according to the creation date. - if (account_order.empty()) { - for (const auto &account : accountFactory.getAllAccounts<T>()) + accountList.reserve(all_accounts.size()); + for (const auto& id : account_order) { + if (auto acc = accountFactory.getAccount<T>(id)) + accountList.push_back(acc); + } + for (const auto& account : all_accounts) { + if (std::find(accountList.begin(), accountList.end(), account) == accountList.end()) accountList.emplace_back(account); - } else { - for (const auto& id : account_order) { - if (auto acc = accountFactory.getAccount<T>(id)) - accountList.push_back(acc); - } } return accountList; } -- GitLab