Simplify loadCardDatabases.

Took 3 minutes

Took 6 seconds
This commit is contained in:
Lukas Brübach 2025-09-25 11:20:19 +02:00
parent f6f4cb6ffd
commit 2b4e62ae41
2 changed files with 19 additions and 16 deletions

View file

@ -290,8 +290,7 @@ LoadStatus CardDatabase::loadCardDatabase(const QString &path)
LoadStatus CardDatabase::loadCardDatabases()
{
reloadDatabaseMutex->lock();
QMutexLocker locker(reloadDatabaseMutex);
qCInfo(CardDatabaseLoadingLog) << "Card Database Loading Started";
clear(); // remove old db
@ -302,24 +301,16 @@ LoadStatus CardDatabase::loadCardDatabases()
// find all custom card databases, recursively & following symlinks
// then load them alphabetically
QDirIterator customDatabaseIterator(SettingsCache::instance().getCustomCardDatabasePath(), QStringList() << "*.xml",
QDir::Files, QDirIterator::Subdirectories | QDirIterator::FollowSymlinks);
QStringList databasePaths;
while (customDatabaseIterator.hasNext()) {
customDatabaseIterator.next();
databasePaths.push_back(customDatabaseIterator.filePath());
}
databasePaths.sort();
for (auto i = 0; i < databasePaths.size(); ++i) {
const auto &databasePath = databasePaths.at(i);
qCInfo(CardDatabaseLoadingLog) << "Loading Custom Set" << i << "(" << databasePath << ")";
loadCardDatabase(databasePath);
for (int i = 0, n = collectCustomDatabasePaths().size(); i < n; ++i) {
const auto &path = collectCustomDatabasePaths().at(i);
qCInfo(CardDatabaseLoadingLog) << "Loading Custom Set" << i << "(" << path << ")";
loadCardDatabase(path);
}
// AFTER all the cards have been loaded
// resolve the reverse-related tags
refreshCachedReverseRelatedCards();
if (loadStatus == Ok) {
@ -331,10 +322,21 @@ LoadStatus CardDatabase::loadCardDatabases()
emit cardDatabaseLoadingFailed(); // bring up the settings dialog
}
reloadDatabaseMutex->unlock();
return loadStatus;
}
QStringList CardDatabase::collectCustomDatabasePaths()
{
QDirIterator it(SettingsCache::instance().getCustomCardDatabasePath(), {"*.xml"}, QDir::Files,
QDirIterator::Subdirectories | QDirIterator::FollowSymlinks);
QStringList paths;
while (it.hasNext())
paths << it.next();
paths.sort();
return paths;
}
/**
* Gets the card representing the preferred printing of the cardInfo
*

View file

@ -113,6 +113,7 @@ public:
void enableAllUnknownSets();
void markAllSetsAsKnown();
void notifyEnabledSetsChanged();
static QStringList collectCustomDatabasePaths();
public slots:
LoadStatus loadCardDatabases();