diff --git a/Telegram/SourceFiles/storage/cache/storage_cache_database.cpp b/Telegram/SourceFiles/storage/cache/storage_cache_database.cpp index f3b25dbdd1..9dab70be54 100644 --- a/Telegram/SourceFiles/storage/cache/storage_cache_database.cpp +++ b/Telegram/SourceFiles/storage/cache/storage_cache_database.cpp @@ -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 &&done) { _wrapped.with([ key = std::move(key), diff --git a/Telegram/SourceFiles/storage/cache/storage_cache_database.h b/Telegram/SourceFiles/storage/cache/storage_cache_database.h index f85e8fbfd2..424f980c25 100644 --- a/Telegram/SourceFiles/storage/cache/storage_cache_database.h +++ b/Telegram/SourceFiles/storage/cache/storage_cache_database.h @@ -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 &&done = nullptr); void close(FnMut &&done = nullptr); diff --git a/Telegram/SourceFiles/storage/cache/storage_cache_database_object.cpp b/Telegram/SourceFiles/storage/cache/storage_cache_database_object.cpp index 437e504114..a41b1a97e4 100644 --- a/Telegram/SourceFiles/storage/cache/storage_cache_database_object.cpp +++ b/Telegram/SourceFiles/storage/cache/storage_cache_database_object.cpp @@ -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 diff --git a/Telegram/SourceFiles/storage/cache/storage_cache_database_object.h b/Telegram/SourceFiles/storage/cache/storage_cache_database_object.h index e90e014799..2014ff1a88 100644 --- a/Telegram/SourceFiles/storage/cache/storage_cache_database_object.h +++ b/Telegram/SourceFiles/storage/cache/storage_cache_database_object.h @@ -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 &&done); void close(FnMut &&done); diff --git a/Telegram/SourceFiles/storage/cache/storage_cache_types.h b/Telegram/SourceFiles/storage/cache/storage_cache_types.h index da76a07f52..415dc6e467 100644 --- a/Telegram/SourceFiles/storage/cache/storage_cache_types.h +++ b/Telegram/SourceFiles/storage/cache/storage_cache_types.h @@ -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);