Clear unused emoji cache with DB.

This commit is contained in:
John Preston 2018-10-24 17:29:19 +04:00
parent bf31722931
commit a961615076
3 changed files with 27 additions and 3 deletions

View File

@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/widgets/shadow.h"
#include "ui/widgets/continuous_sliders.h"
#include "ui/effects/radial_animation.h"
#include "ui/emoji_config.h"
#include "storage/localstorage.h"
#include "storage/cache/storage_cache_database.h"
#include "data/data_session.h"
@ -316,6 +317,7 @@ void LocalStorageBox::clearByTag(uint8 tag) {
_db->clearByTag(tag);
} else {
_db->clear();
Ui::Emoji::ClearIrrelevantCache();
}
}

View File

@ -65,11 +65,14 @@ QString CacheFileFolder() {
return cWorkingDir() + "tdata/emoji";
}
QString CacheFileNameMask(int size) {
return "cache_" + QString::number(size) + '_';
}
QString CacheFilePath(int size, int index) {
return CacheFileFolder()
+ "/cache_"
+ QString::number(size)
+ '_'
+ '/'
+ CacheFileNameMask(size)
+ QString::number(index);
}
@ -323,6 +326,23 @@ void Clear() {
InstanceLarge = nullptr;
}
void ClearIrrelevantCache() {
Expects(SizeNormal > 0);
Expects(SizeLarge > 0);
crl::async([] {
const auto folder = CacheFileFolder();
const auto list = QDir(folder).entryList(QDir::Files);
const auto good1 = CacheFileNameMask(SizeNormal);
const auto good2 = CacheFileNameMask(SizeLarge);
for (const auto &name : list) {
if (!name.startsWith(good1) && !name.startsWith(good2)) {
QFile(folder + '/' + name).remove();
}
}
});
}
int GetSizeNormal() {
Expects(SizeNormal > 0);

View File

@ -18,6 +18,8 @@ constexpr auto kRecentLimit = 42;
void Init();
void Clear();
void ClearIrrelevantCache();
int GetSizeNormal();
int GetSizeLarge();