Implement media cache management.

This commit is contained in:
John Preston 2019-03-01 18:20:04 +04:00
parent 1940c67a09
commit e631d98230
7 changed files with 228 additions and 68 deletions

View File

@ -436,7 +436,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_local_storage_round#other" = "{count} video messages"; "lng_local_storage_round#other" = "{count} video messages";
"lng_local_storage_animation#one" = "{count} animation"; "lng_local_storage_animation#one" = "{count} animation";
"lng_local_storage_animation#other" = "{count} animations"; "lng_local_storage_animation#other" = "{count} animations";
"lng_local_storage_media" = "Media cache";
"lng_local_storage_size_limit" = "Total size limit: {size}"; "lng_local_storage_size_limit" = "Total size limit: {size}";
"lng_local_storage_media_limit" = "Media cache limit: {size}";
"lng_local_storage_time_limit" = "Clear files older than: {limit}"; "lng_local_storage_time_limit" = "Clear files older than: {limit}";
"lng_local_storage_limit_weeks#one" = "{count} week"; "lng_local_storage_limit_weeks#one" = "{count} week";
"lng_local_storage_limit_weeks#other" = "{count} weeks"; "lng_local_storage_limit_weeks#other" = "{count} weeks";

View File

@ -26,19 +26,34 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace { namespace {
constexpr auto kSizeLimitsCount = 20; constexpr auto kMegabyte = int64(1024 * 1024);
constexpr auto kTotalSizeLimitsCount = 18;
constexpr auto kMediaSizeLimitsCount = 18;
constexpr auto kMinimalSizeLimit = 100 * kMegabyte;
constexpr auto kTimeLimitsCount = 16; constexpr auto kTimeLimitsCount = 16;
constexpr auto kMaxTimeLimitValue = std::numeric_limits<size_type>::max(); constexpr auto kMaxTimeLimitValue = std::numeric_limits<size_type>::max();
constexpr auto kFakeMediaCacheTag = uint16(0xFFFF);
int64 SizeLimitInMB(int index) { int64 TotalSizeLimitInMB(int index) {
if (index < 10) { if (index < 8) {
return int64(index + 1) * 100; return int64(index + 2) * 100;
} }
return int64(index - 9) * 1024; return int64(index - 7) * 1024;
} }
int64 SizeLimit(int index) { int64 TotalSizeLimit(int index) {
return SizeLimitInMB(index) * 1024 * 1024; return TotalSizeLimitInMB(index) * kMegabyte;
}
int64 MediaSizeLimitInMB(int index) {
if (index < 9) {
return int64(index + 1) * 100;
}
return int64(index - 8) * 1024;
}
int64 MediaSizeLimit(int index) {
return MediaSizeLimitInMB(index) * kMegabyte;
} }
QString SizeLimitText(int64 limit) { QString SizeLimitText(int64 limit) {
@ -255,20 +270,30 @@ QString LocalStorageBox::Row::sizeText(const Database::TaggedSummary &data) cons
LocalStorageBox::LocalStorageBox( LocalStorageBox::LocalStorageBox(
QWidget*, QWidget*,
not_null<Database*> db, not_null<Database*> db,
not_null<Database*> dbBig,
CreateTag) CreateTag)
: _db(db) { : _db(db)
, _dbBig(dbBig) {
const auto &settings = Local::cacheSettings(); const auto &settings = Local::cacheSettings();
_sizeLimit = settings.totalSizeLimit; const auto &settingsBig = Local::cacheBigFileSettings();
_totalSizeLimit = settings.totalSizeLimit + settingsBig.totalSizeLimit;
_mediaSizeLimit = settingsBig.totalSizeLimit;
_timeLimit = settings.totalTimeLimit; _timeLimit = settings.totalTimeLimit;
} }
void LocalStorageBox::Show(not_null<Database*> db) { void LocalStorageBox::Show(
not_null<Database*> db,
not_null<Database*> dbBig) {
auto shared = std::make_shared<object_ptr<LocalStorageBox>>( auto shared = std::make_shared<object_ptr<LocalStorageBox>>(
Box<LocalStorageBox>(db, CreateTag())); Box<LocalStorageBox>(db, dbBig, CreateTag()));
const auto weak = shared->data(); const auto weak = shared->data();
db->statsOnMain( rpl::combine(
) | rpl::start_with_next([=](Database::Stats &&stats) { db->statsOnMain(),
weak->update(std::move(stats)); dbBig->statsOnMain()
) | rpl::start_with_next([=](
Database::Stats &&stats,
Database::Stats &&statsBig) {
weak->update(std::move(stats), std::move(statsBig));
if (auto &strong = *shared) { if (auto &strong = *shared) {
Ui::show(std::move(strong)); Ui::show(std::move(strong));
} }
@ -285,7 +310,7 @@ void LocalStorageBox::prepare() {
void LocalStorageBox::updateRow( void LocalStorageBox::updateRow(
not_null<Ui::SlideWrap<Row>*> row, not_null<Ui::SlideWrap<Row>*> row,
Database::TaggedSummary *data) { const Database::TaggedSummary *data) {
const auto summary = (_rows.find(0)->second == row); const auto summary = (_rows.find(0)->second == row);
const auto shown = (data && data->count && data->totalSize) || summary; const auto shown = (data && data->count && data->totalSize) || summary;
if (shown) { if (shown) {
@ -294,28 +319,45 @@ void LocalStorageBox::updateRow(
row->toggle(shown, anim::type::normal); row->toggle(shown, anim::type::normal);
} }
void LocalStorageBox::update(Database::Stats &&stats) { void LocalStorageBox::update(
Database::Stats &&stats,
Database::Stats &&statsBig) {
_stats = std::move(stats); _stats = std::move(stats);
_statsBig = std::move(statsBig);
if (const auto i = _rows.find(0); i != end(_rows)) { if (const auto i = _rows.find(0); i != end(_rows)) {
i->second->entity()->toggleProgress(_stats.clearing); i->second->entity()->toggleProgress(
_stats.clearing || _statsBig.clearing);
} }
for (const auto &entry : _rows) { for (const auto &entry : _rows) {
if (entry.first) { if (entry.first == kFakeMediaCacheTag) {
updateRow(entry.second, &_statsBig.full);
} else if (entry.first) {
const auto i = _stats.tagged.find(entry.first); const auto i = _stats.tagged.find(entry.first);
updateRow( updateRow(
entry.second, entry.second,
(i != end(_stats.tagged)) ? &i->second : nullptr); (i != end(_stats.tagged)) ? &i->second : nullptr);
} else { } else {
updateRow(entry.second, &_stats.full); const auto full = summary();
updateRow(entry.second, &full);
} }
} }
} }
void LocalStorageBox::clearByTag(uint8 tag) { auto LocalStorageBox::summary() const -> Database::TaggedSummary {
if (tag) { auto result = _stats.full;
result.count += _statsBig.full.count;
result.totalSize += _statsBig.full.totalSize;
return result;
}
void LocalStorageBox::clearByTag(uint16 tag) {
if (tag == kFakeMediaCacheTag) {
_dbBig->clear();
} else if (tag) {
_db->clearByTag(tag); _db->clearByTag(tag);
} else { } else {
_db->clear(); _db->clear();
_dbBig->clear();
Ui::Emoji::ClearIrrelevantCache(); Ui::Emoji::ClearIrrelevantCache();
} }
} }
@ -325,7 +367,7 @@ void LocalStorageBox::setupControls() {
object_ptr<Ui::VerticalLayout>(this), object_ptr<Ui::VerticalLayout>(this),
st::contactsMultiSelect.scroll); st::contactsMultiSelect.scroll);
const auto createRow = [&]( const auto createRow = [&](
uint8 tag, uint16 tag,
Fn<QString(size_type)> title, Fn<QString(size_type)> title,
Fn<QString()> clear, Fn<QString()> clear,
const Database::TaggedSummary &data) { const Database::TaggedSummary &data) {
@ -363,11 +405,14 @@ void LocalStorageBox::setupControls() {
auto summaryTitle = [](size_type) { auto summaryTitle = [](size_type) {
return lang(lng_local_storage_summary); return lang(lng_local_storage_summary);
}; };
auto mediaCacheTitle = [](size_type) {
return lang(lng_local_storage_media);
};
createRow( createRow(
0, 0,
std::move(summaryTitle), std::move(summaryTitle),
langFactory(lng_local_storage_clear), langFactory(lng_local_storage_clear),
_stats.full); summary());
setupLimits(container); setupLimits(container);
const auto shadow = container->add(object_ptr<Ui::SlideWrap<>>( const auto shadow = container->add(object_ptr<Ui::SlideWrap<>>(
container, container,
@ -378,6 +423,11 @@ void LocalStorageBox::setupControls() {
createTagRow(Data::kVoiceMessageCacheTag, lng_local_storage_voice); createTagRow(Data::kVoiceMessageCacheTag, lng_local_storage_voice);
createTagRow(Data::kVideoMessageCacheTag, lng_local_storage_round); createTagRow(Data::kVideoMessageCacheTag, lng_local_storage_round);
createTagRow(Data::kAnimationCacheTag, lng_local_storage_animation); createTagRow(Data::kAnimationCacheTag, lng_local_storage_animation);
tracker.track(createRow(
kFakeMediaCacheTag,
std::move(mediaCacheTitle),
langFactory(lng_local_storage_clear_some),
_statsBig.full));
shadow->toggleOn( shadow->toggleOn(
std::move(tracker).atLeastOneShownValue() std::move(tracker).atLeastOneShownValue()
); );
@ -393,7 +443,7 @@ template <
typename Convert, typename Convert,
typename Callback, typename Callback,
typename> typename>
void LocalStorageBox::createLimitsSlider( not_null<Ui::MediaSlider*> LocalStorageBox::createLimitsSlider(
not_null<Ui::VerticalLayout*> container, not_null<Ui::VerticalLayout*> container,
int valuesCount, int valuesCount,
Convert &&convert, Convert &&convert,
@ -414,6 +464,60 @@ void LocalStorageBox::createLimitsSlider(
[=, callback = std::forward<Callback>(callback)](Value value) { [=, callback = std::forward<Callback>(callback)](Value value) {
callback(label, value); callback(label, value);
}); });
return slider;
}
void LocalStorageBox::updateMediaLimit() {
const auto good = [&](int64 mediaLimit) {
return (_totalSizeLimit - mediaLimit >= kMinimalSizeLimit);
};
if (good(_mediaSizeLimit) || !_mediaSlider || !_mediaLabel) {
return;
}
auto index = 1;
while ((index < kMediaSizeLimitsCount)
&& (MediaSizeLimit(index) * 2 <= _totalSizeLimit)) {
++index;
}
--index;
_mediaSizeLimit = MediaSizeLimit(index);
_mediaSlider->setValue(index / float64(kMediaSizeLimitsCount - 1));
updateMediaLabel();
Ensures(good(_mediaSizeLimit));
}
void LocalStorageBox::updateTotalLimit() {
const auto good = [&](int64 totalLimit) {
return (totalLimit - _mediaSizeLimit >= kMinimalSizeLimit);
};
if (good(_totalSizeLimit) || !_totalSlider || !_totalLabel) {
return;
}
auto index = kTotalSizeLimitsCount - 1;
while ((index > 0)
&& (TotalSizeLimit(index - 1) >= 2 * _mediaSizeLimit)) {
--index;
}
_totalSizeLimit = TotalSizeLimit(index);
_totalSlider->setValue(index / float64(kTotalSizeLimitsCount - 1));
updateTotalLabel();
Ensures(good(_totalSizeLimit));
}
void LocalStorageBox::updateTotalLabel() {
Expects(_totalLabel != nullptr);
const auto text = SizeLimitText(_totalSizeLimit);
_totalLabel->setText(lng_local_storage_size_limit(lt_size, text));
}
void LocalStorageBox::updateMediaLabel() {
Expects(_mediaLabel != nullptr);
const auto text = SizeLimitText(_mediaSizeLimit);
_mediaLabel->setText(lng_local_storage_media_limit(lt_size, text));
} }
void LocalStorageBox::setupLimits(not_null<Ui::VerticalLayout*> container) { void LocalStorageBox::setupLimits(not_null<Ui::VerticalLayout*> container) {
@ -421,15 +525,29 @@ void LocalStorageBox::setupLimits(not_null<Ui::VerticalLayout*> container) {
object_ptr<Ui::PlainShadow>(container), object_ptr<Ui::PlainShadow>(container),
st::localStorageRowPadding); st::localStorageRowPadding);
createLimitsSlider( _totalSlider = createLimitsSlider(
container, container,
kSizeLimitsCount, kTotalSizeLimitsCount,
SizeLimit, TotalSizeLimit,
_sizeLimit, _totalSizeLimit,
[=](not_null<Ui::LabelSimple*> label, int64 limit) { [=](not_null<Ui::LabelSimple*> label, int64 limit) {
const auto text = SizeLimitText(limit); _totalSizeLimit = limit;
label->setText(lng_local_storage_size_limit(lt_size, text)); _totalLabel = label;
_sizeLimit = limit; updateTotalLabel();
updateMediaLimit();
limitsChanged();
});
_mediaSlider = createLimitsSlider(
container,
kMediaSizeLimitsCount,
MediaSizeLimit,
_mediaSizeLimit,
[=](not_null<Ui::LabelSimple*> label, int64 limit) {
_mediaSizeLimit = limit;
_mediaLabel = label;
updateMediaLabel();
updateTotalLimit();
limitsChanged(); limitsChanged();
}); });
@ -448,8 +566,12 @@ void LocalStorageBox::setupLimits(not_null<Ui::VerticalLayout*> container) {
void LocalStorageBox::limitsChanged() { void LocalStorageBox::limitsChanged() {
const auto &settings = Local::cacheSettings(); const auto &settings = Local::cacheSettings();
const auto changed = (settings.totalSizeLimit != _sizeLimit) const auto &settingsBig = Local::cacheBigFileSettings();
|| (settings.totalTimeLimit != _timeLimit); const auto sizeLimit = _totalSizeLimit - _mediaSizeLimit;
const auto changed = (settings.totalSizeLimit != sizeLimit)
|| (settingsBig.totalSizeLimit != _mediaSizeLimit)
|| (settings.totalTimeLimit != _timeLimit)
|| (settingsBig.totalTimeLimit != _timeLimit);
if (_limitsChanged != changed) { if (_limitsChanged != changed) {
_limitsChanged = changed; _limitsChanged = changed;
clearButtons(); clearButtons();
@ -468,10 +590,12 @@ void LocalStorageBox::save() {
return; return;
} }
auto update = Storage::Cache::Database::SettingsUpdate(); auto update = Storage::Cache::Database::SettingsUpdate();
update.totalSizeLimit = _sizeLimit; update.totalSizeLimit = _totalSizeLimit - _mediaSizeLimit;
update.totalTimeLimit = _timeLimit; update.totalTimeLimit = _timeLimit;
Local::updateCacheSettings(update); auto updateBig = Storage::Cache::Database::SettingsUpdate();
Local::updateCacheBigFileSettings(update); updateBig.totalSizeLimit = _mediaSizeLimit;
update.totalTimeLimit = _timeLimit;
Local::updateCacheSettings(update, updateBig);
Auth().data().cache().updateSettings(update); Auth().data().cache().updateSettings(update);
closeBox(); closeBox();
} }

View File

@ -21,6 +21,7 @@ class VerticalLayout;
template <typename Widget> template <typename Widget>
class SlideWrap; class SlideWrap;
class LabelSimple; class LabelSimple;
class MediaSlider;
} // namespace Ui } // namespace Ui
class LocalStorageBox : public BoxContent { class LocalStorageBox : public BoxContent {
@ -30,9 +31,13 @@ class LocalStorageBox : public BoxContent {
public: public:
using Database = Storage::Cache::Database; using Database = Storage::Cache::Database;
LocalStorageBox(QWidget*, not_null<Database*> db, CreateTag); LocalStorageBox(
QWidget*,
not_null<Database*> db,
not_null<Database*> dbBig,
CreateTag);
static void Show(not_null<Database*> db); static void Show(not_null<Database*> db, not_null<Database*> dbBig);
protected: protected:
void prepare() override; void prepare() override;
@ -42,16 +47,22 @@ protected:
private: private:
class Row; class Row;
void clearByTag(uint8 tag); void clearByTag(uint16 tag);
void update(Database::Stats &&stats); void update(Database::Stats &&stats, Database::Stats &&statsBig);
void updateRow( void updateRow(
not_null<Ui::SlideWrap<Row>*> row, not_null<Ui::SlideWrap<Row>*> row,
Database::TaggedSummary *data); const Database::TaggedSummary *data);
void setupControls(); void setupControls();
void setupLimits(not_null<Ui::VerticalLayout*> container); void setupLimits(not_null<Ui::VerticalLayout*> container);
void updateMediaLimit();
void updateTotalLimit();
void updateTotalLabel();
void updateMediaLabel();
void limitsChanged(); void limitsChanged();
void save(); void save();
Database::TaggedSummary summary() const;
template < template <
typename Value, typename Value,
typename Convert, typename Convert,
@ -62,7 +73,7 @@ private:
not_null<Ui::LabelSimple*>, not_null<Ui::LabelSimple*>,
Value> Value>
&& std::is_same_v<Value, decltype(std::declval<Convert>()(1))>>> && std::is_same_v<Value, decltype(std::declval<Convert>()(1))>>>
void createLimitsSlider( not_null<Ui::MediaSlider*> createLimitsSlider(
not_null<Ui::VerticalLayout*> container, not_null<Ui::VerticalLayout*> container,
int valuesCount, int valuesCount,
Convert &&convert, Convert &&convert,
@ -70,11 +81,18 @@ private:
Callback &&callback); Callback &&callback);
not_null<Storage::Cache::Database*> _db; not_null<Storage::Cache::Database*> _db;
not_null<Storage::Cache::Database*> _dbBig;
Database::Stats _stats; Database::Stats _stats;
Database::Stats _statsBig;
base::flat_map<uint8, not_null<Ui::SlideWrap<Row>*>> _rows; base::flat_map<uint16, not_null<Ui::SlideWrap<Row>*>> _rows;
Ui::MediaSlider *_totalSlider = nullptr;
Ui::LabelSimple *_totalLabel = nullptr;
Ui::MediaSlider *_mediaSlider = nullptr;
Ui::LabelSimple *_mediaLabel = nullptr;
int64 _sizeLimit = 0; int64 _totalSizeLimit = 0;
int64 _mediaSizeLimit = 0;
size_type _timeLimit = 0; size_type _timeLimit = 0;
bool _limitsChanged = false; bool _limitsChanged = false;

View File

@ -570,7 +570,9 @@ void SetupLocalStorage(not_null<Ui::VerticalLayout*> container) {
lng_settings_manage_local_storage, lng_settings_manage_local_storage,
st::settingsButton st::settingsButton
)->addClickHandler([] { )->addClickHandler([] {
LocalStorageBox::Show(&Auth().data().cache()); LocalStorageBox::Show(
&Auth().data().cache(),
&Auth().data().cacheBigFile());
}); });
} }

View File

@ -602,12 +602,13 @@ enum {
dbiTxtDomainString = 0x53, dbiTxtDomainString = 0x53,
dbiThemeKey = 0x54, dbiThemeKey = 0x54,
dbiTileBackground = 0x55, dbiTileBackground = 0x55,
dbiCacheSettings = 0x56, dbiCacheSettingsOld = 0x56,
dbiAnimationsDisabled = 0x57, dbiAnimationsDisabled = 0x57,
dbiScalePercent = 0x58, dbiScalePercent = 0x58,
dbiPlaybackSpeed = 0x59, dbiPlaybackSpeed = 0x59,
dbiLanguagesKey = 0x5a, dbiLanguagesKey = 0x5a,
dbiCallSettings = 0x5b, dbiCallSettings = 0x5b,
dbiCacheSettings = 0x5c,
dbiEncryptedWithSalt = 333, dbiEncryptedWithSalt = 333,
dbiEncrypted = 444, dbiEncrypted = 444,
@ -1071,7 +1072,7 @@ bool _readSetting(quint32 blockId, QDataStream &stream, int version, ReadSetting
cSetUseExternalVideoPlayer(v == 1); cSetUseExternalVideoPlayer(v == 1);
} break; } break;
case dbiCacheSettings: { case dbiCacheSettingsOld: {
qint64 size; qint64 size;
qint32 time; qint32 time;
stream >> size >> time; stream >> size >> time;
@ -1080,11 +1081,28 @@ bool _readSetting(quint32 blockId, QDataStream &stream, int version, ReadSetting
|| time < 0) { || time < 0) {
return false; return false;
} }
_cacheTotalSizeLimit = size; _cacheTotalSizeLimit = size;
_cacheTotalTimeLimit = time; _cacheTotalTimeLimit = time;
_cacheBigFileTotalSizeLimit = size; _cacheBigFileTotalSizeLimit = size;
_cacheBigFileTotalTimeLimit = size; _cacheBigFileTotalTimeLimit = time;
} break;
case dbiCacheSettings: {
qint64 size, sizeBig;
qint32 time, timeBig;
stream >> size >> time >> sizeBig >> timeBig;
if (!_checkStreamStatus(stream)
|| size <= Database::Settings().maxDataSize
|| sizeBig <= Database::Settings().maxDataSize
|| time < 0
|| timeBig < 0) {
return false;
}
_cacheTotalSizeLimit = size;
_cacheTotalTimeLimit = time;
_cacheBigFileTotalSizeLimit = sizeBig;
_cacheBigFileTotalTimeLimit = timeBig;
} break; } break;
case dbiAnimationsDisabled: { case dbiAnimationsDisabled: {
@ -2108,8 +2126,7 @@ void _writeUserSettings() {
data.stream << quint32(dbiModerateMode) << qint32(Global::ModerateModeEnabled() ? 1 : 0); data.stream << quint32(dbiModerateMode) << qint32(Global::ModerateModeEnabled() ? 1 : 0);
data.stream << quint32(dbiAutoPlay) << qint32(cAutoPlayGif() ? 1 : 0); data.stream << quint32(dbiAutoPlay) << qint32(cAutoPlayGif() ? 1 : 0);
data.stream << quint32(dbiUseExternalVideoPlayer) << qint32(cUseExternalVideoPlayer()); data.stream << quint32(dbiUseExternalVideoPlayer) << qint32(cUseExternalVideoPlayer());
data.stream << quint32(dbiCacheSettings) << qint64(_cacheTotalSizeLimit) << qint32(_cacheTotalTimeLimit); data.stream << quint32(dbiCacheSettings) << qint64(_cacheTotalSizeLimit) << qint32(_cacheTotalTimeLimit) << qint64(_cacheBigFileTotalSizeLimit) << qint32(_cacheBigFileTotalTimeLimit);
// #TODO streaming save _cacheBigFileTotal limits?..
if (!userData.isEmpty()) { if (!userData.isEmpty()) {
data.stream << quint32(dbiAuthSessionSettings) << userData; data.stream << quint32(dbiAuthSessionSettings) << userData;
} }
@ -3208,16 +3225,24 @@ Storage::Cache::Database::Settings cacheSettings() {
return result; return result;
} }
void updateCacheSettings(Storage::Cache::Database::SettingsUpdate &update) { void updateCacheSettings(
Storage::Cache::Database::SettingsUpdate &update,
Storage::Cache::Database::SettingsUpdate &updateBig) {
Expects(update.totalSizeLimit > Database::Settings().maxDataSize); Expects(update.totalSizeLimit > Database::Settings().maxDataSize);
Expects(update.totalTimeLimit >= 0); Expects(update.totalTimeLimit >= 0);
Expects(updateBig.totalSizeLimit > Database::Settings().maxDataSize);
Expects(updateBig.totalTimeLimit >= 0);
if (_cacheTotalSizeLimit == update.totalSizeLimit if (_cacheTotalSizeLimit == update.totalSizeLimit
&& _cacheTotalTimeLimit == update.totalTimeLimit) { && _cacheTotalTimeLimit == update.totalTimeLimit
&& _cacheBigFileTotalSizeLimit == updateBig.totalSizeLimit
&& _cacheBigFileTotalTimeLimit == updateBig.totalTimeLimit) {
return; return;
} }
_cacheTotalSizeLimit = update.totalSizeLimit; _cacheTotalSizeLimit = update.totalSizeLimit;
_cacheTotalTimeLimit = update.totalTimeLimit; _cacheTotalTimeLimit = update.totalTimeLimit;
_cacheBigFileTotalSizeLimit = updateBig.totalSizeLimit;
_cacheBigFileTotalTimeLimit = updateBig.totalTimeLimit;
_writeUserSettings(); _writeUserSettings();
} }
@ -3236,19 +3261,6 @@ Storage::Cache::Database::Settings cacheBigFileSettings() {
return result; return result;
} }
void updateCacheBigFileSettings(Storage::Cache::Database::SettingsUpdate &update) {
Expects(update.totalSizeLimit > Database::Settings().maxDataSize);
Expects(update.totalTimeLimit >= 0);
if (_cacheBigFileTotalSizeLimit == update.totalSizeLimit
&& _cacheBigFileTotalTimeLimit == update.totalTimeLimit) {
return;
}
_cacheBigFileTotalSizeLimit = update.totalSizeLimit;
_cacheBigFileTotalTimeLimit = update.totalTimeLimit;
//_writeUserSettings(); // #TODO streaming save those?..
}
class CountWaveformTask : public Task { class CountWaveformTask : public Task {
public: public:
CountWaveformTask(DocumentData *doc) CountWaveformTask(DocumentData *doc)

View File

@ -115,12 +115,13 @@ FileLocation readFileLocation(MediaKey location, bool check = true);
Storage::EncryptionKey cacheKey(); Storage::EncryptionKey cacheKey();
QString cachePath(); QString cachePath();
Storage::Cache::Database::Settings cacheSettings(); Storage::Cache::Database::Settings cacheSettings();
void updateCacheSettings(Storage::Cache::Database::SettingsUpdate &update); void updateCacheSettings(
Storage::Cache::Database::SettingsUpdate &update,
Storage::Cache::Database::SettingsUpdate &updateBig);
Storage::EncryptionKey cacheBigFileKey(); Storage::EncryptionKey cacheBigFileKey();
QString cacheBigFilePath(); QString cacheBigFilePath();
Storage::Cache::Database::Settings cacheBigFileSettings(); Storage::Cache::Database::Settings cacheBigFileSettings();
void updateCacheBigFileSettings(Storage::Cache::Database::SettingsUpdate &update);
void countVoiceWaveform(DocumentData *document); void countVoiceWaveform(DocumentData *document);

View File

@ -152,6 +152,7 @@ public:
setDirection(Ui::ContinuousSlider::Direction::Horizontal); setDirection(Ui::ContinuousSlider::Direction::Horizontal);
const auto sectionsCount = (valuesCount - 1); const auto sectionsCount = (valuesCount - 1);
setValue(1.);
for (auto index = index_type(); index != valuesCount; ++index) { for (auto index = index_type(); index != valuesCount; ++index) {
if (current <= convert(index)) { if (current <= convert(index)) {
setValue(index / float64(sectionsCount)); setValue(index / float64(sectionsCount));