mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-01-11 17:29:46 +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/shadow.h"
|
||||||
#include "ui/widgets/continuous_sliders.h"
|
#include "ui/widgets/continuous_sliders.h"
|
||||||
#include "ui/effects/radial_animation.h"
|
#include "ui/effects/radial_animation.h"
|
||||||
|
#include "ui/emoji_config.h"
|
||||||
#include "storage/localstorage.h"
|
#include "storage/localstorage.h"
|
||||||
#include "storage/cache/storage_cache_database.h"
|
#include "storage/cache/storage_cache_database.h"
|
||||||
#include "data/data_session.h"
|
#include "data/data_session.h"
|
||||||
@ -316,6 +317,7 @@ void LocalStorageBox::clearByTag(uint8 tag) {
|
|||||||
_db->clearByTag(tag);
|
_db->clearByTag(tag);
|
||||||
} else {
|
} else {
|
||||||
_db->clear();
|
_db->clear();
|
||||||
|
Ui::Emoji::ClearIrrelevantCache();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,11 +65,14 @@ QString CacheFileFolder() {
|
|||||||
return cWorkingDir() + "tdata/emoji";
|
return cWorkingDir() + "tdata/emoji";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString CacheFileNameMask(int size) {
|
||||||
|
return "cache_" + QString::number(size) + '_';
|
||||||
|
}
|
||||||
|
|
||||||
QString CacheFilePath(int size, int index) {
|
QString CacheFilePath(int size, int index) {
|
||||||
return CacheFileFolder()
|
return CacheFileFolder()
|
||||||
+ "/cache_"
|
+ '/'
|
||||||
+ QString::number(size)
|
+ CacheFileNameMask(size)
|
||||||
+ '_'
|
|
||||||
+ QString::number(index);
|
+ QString::number(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -323,6 +326,23 @@ void Clear() {
|
|||||||
InstanceLarge = nullptr;
|
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() {
|
int GetSizeNormal() {
|
||||||
Expects(SizeNormal > 0);
|
Expects(SizeNormal > 0);
|
||||||
|
|
||||||
|
@ -18,6 +18,8 @@ constexpr auto kRecentLimit = 42;
|
|||||||
void Init();
|
void Init();
|
||||||
void Clear();
|
void Clear();
|
||||||
|
|
||||||
|
void ClearIrrelevantCache();
|
||||||
|
|
||||||
int GetSizeNormal();
|
int GetSizeNormal();
|
||||||
int GetSizeLarge();
|
int GetSizeLarge();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user