mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-06 05:23:56 -07:00
Add batch write function
Took 24 minutes Took 5 seconds Took 26 seconds
This commit is contained in:
parent
21d8e6b9ad
commit
8f9dad8966
9 changed files with 61 additions and 7 deletions
|
|
@ -34,3 +34,17 @@ bool CardDatabaseSettings::isKnown(QString shortName) const
|
|||
{
|
||||
return getValue("isknown", "sets", std::move(shortName)).toBool();
|
||||
}
|
||||
|
||||
void CardDatabaseSettings::saveSets(const QVector<ICardSetPriorityController::SetSaveData> &data)
|
||||
{
|
||||
batchWrite([&](QSettings &s) {
|
||||
s.beginGroup("sets");
|
||||
for (const auto &entry : data) {
|
||||
s.beginGroup(entry.shortName);
|
||||
s.setValue("sortkey", entry.sortKey);
|
||||
s.setValue("enabled", entry.enabled);
|
||||
s.endGroup();
|
||||
}
|
||||
s.endGroup();
|
||||
});
|
||||
}
|
||||
|
|
@ -26,6 +26,8 @@ public:
|
|||
bool isEnabled(QString shortName) const override;
|
||||
bool isKnown(QString shortName) const override;
|
||||
|
||||
void saveSets(const QVector<SetSaveData> &data) override;
|
||||
|
||||
private:
|
||||
explicit CardDatabaseSettings(const QString &settingPath, QObject *parent = nullptr);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -159,6 +159,15 @@ QVariant SettingsManager::getValue(const QString &name, const QString &group, co
|
|||
return value;
|
||||
}
|
||||
|
||||
void SettingsManager::batchWrite(std::function<void(QSettings &)> batchWriteFunction)
|
||||
{
|
||||
auto settings = getSettings();
|
||||
settings.setAtomicSyncRequired(false);
|
||||
batchWriteFunction(settings);
|
||||
settings.sync(); // single flush
|
||||
settings.setAtomicSyncRequired(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls sync on the underlying QSettings object
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ public:
|
|||
|
||||
QVariant getValue(const QString &name) const;
|
||||
QVariant getValue(const QString &name, const QString &group, const QString &subGroup = QString()) const;
|
||||
void batchWrite(std::function<void(QSettings &)> batchWriteFunction);
|
||||
|
||||
void sync();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue