Allow updating some database settings.

This commit is contained in:
John Preston 2018-08-31 14:37:22 +03:00
parent 55fe977d54
commit 5733f4079f
5 changed files with 23 additions and 1 deletions

View File

@ -22,6 +22,12 @@ void Database::reconfigure(const Settings &settings) {
});
}
void Database::updateSettings(const SettingsUpdate &update) {
_wrapped.with([update](Implementation &unwrapped) mutable {
unwrapped.updateSettings(update);
});
}
void Database::open(EncryptionKey &&key, FnMut<void(Error)> &&done) {
_wrapped.with([
key = std::move(key),

View File

@ -24,9 +24,11 @@ class DatabaseObject;
class Database {
public:
using Settings = details::Settings;
using SettingsUpdate = details::SettingsUpdate;
Database(const QString &path, const Settings &settings);
void reconfigure(const Settings &settings);
void updateSettings(const SettingsUpdate &update);
void open(EncryptionKey &&key, FnMut<void(Error)> &&done = nullptr);
void close(FnMut<void()> &&done = nullptr);

View File

@ -92,6 +92,14 @@ void DatabaseObject::reconfigure(const Settings &settings) {
checkSettings();
}
void DatabaseObject::updateSettings(const SettingsUpdate &update) {
_settings.totalSizeLimit = update.totalSizeLimit;
_settings.totalTimeLimit = update.totalTimeLimit;
checkSettings();
optimize();
}
void DatabaseObject::checkSettings() {
Expects(_settings.staleRemoveChunk > 0);
Expects(_settings.maxDataSize > 0

View File

@ -31,6 +31,7 @@ public:
const QString &path,
const Settings &settings);
void reconfigure(const Settings &settings);
void updateSettings(const SettingsUpdate &update);
void open(EncryptionKey &&key, FnMut<void(Error)> &&done);
void close(FnMut<void()> &&done);

View File

@ -66,13 +66,18 @@ struct Settings {
bool trackEstimatedTime = true;
int64 totalSizeLimit = 1024 * 1024 * 1024;
size_type totalTimeLimit = 30 * 86400; // One month in seconds.
size_type totalTimeLimit = 31 * 24 * 60 * 60; // One month in seconds.
crl::time_type pruneTimeout = 5 * crl::time_type(1000);
crl::time_type maxPruneCheckTimeout = 3600 * crl::time_type(1000);
bool clearOnWrongKey = false;
};
struct SettingsUpdate {
int64 totalSizeLimit = Settings().totalSizeLimit;
size_type totalTimeLimit = Settings().totalTimeLimit;
};
struct TaggedValue {
TaggedValue() = default;
TaggedValue(QByteArray &&bytes, uint8 tag);