mirror of
https://github.com/telegramdesktop/tdesktop
synced 2024-12-23 23:14:41 +00:00
Clear unused emoji cache with DB.
This commit is contained in:
parent
bf31722931
commit
a961615076
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
@ -18,6 +18,8 @@ constexpr auto kRecentLimit = 42;
|
||||
void Init();
|
||||
void Clear();
|
||||
|
||||
void ClearIrrelevantCache();
|
||||
|
||||
int GetSizeNormal();
|
||||
int GetSizeLarge();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user