Stickers cache TTL
This commit is contained in:
parent
7500e14f35
commit
f316222a45
3
src/layer.d.ts
vendored
3
src/layer.d.ts
vendored
@ -3852,7 +3852,8 @@ export namespace MessagesStickerSet {
|
||||
_: 'messages.stickerSet',
|
||||
set: StickerSet,
|
||||
packs: Array<StickerPack>,
|
||||
documents: Array<Document>
|
||||
documents: Array<Document>,
|
||||
refreshTime?: number
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ import AppStorage from '../storage';
|
||||
import { MOUNT_CLASS_TO } from '../../config/debug';
|
||||
import { forEachReverse } from '../../helpers/array';
|
||||
|
||||
// TODO: если пак будет сохранён и потом обновлён, то недостающие стикеры не подгрузит
|
||||
const CACHE_TIME = 3600e3;
|
||||
|
||||
export class AppStickersManager {
|
||||
private storage = new AppStorage<Record<string, MessagesStickerSet>>({
|
||||
@ -53,10 +53,10 @@ export class AppStickersManager {
|
||||
return this.getStickerSetPromises[set.id];
|
||||
}
|
||||
|
||||
return this.getStickerSetPromises[set.id] = new Promise(async(resolve, reject) => {
|
||||
return this.getStickerSetPromises[set.id] = new Promise(async(resolve) => {
|
||||
if(!params.overwrite) {
|
||||
const cachedSet = await this.storage.get(set.id);
|
||||
if(cachedSet && cachedSet.documents?.length) {
|
||||
if(cachedSet && cachedSet.documents?.length && (Date.now() - cachedSet.refreshTime) < CACHE_TIME) {
|
||||
this.saveStickers(cachedSet.documents);
|
||||
resolve(cachedSet);
|
||||
delete this.getStickerSetPromises[set.id];
|
||||
@ -120,6 +120,7 @@ export class AppStickersManager {
|
||||
|
||||
//console.log('stickers wrote', this.stickerSets);
|
||||
const needSave = stickerSet.set.installed_date || id === 'emoji';
|
||||
stickerSet.refreshTime = Date.now();
|
||||
this.storage.set({[id]: stickerSet}, !needSave);
|
||||
}
|
||||
|
||||
|
@ -214,4 +214,9 @@
|
||||
{"name": "channel_id", "type": "number"}
|
||||
],
|
||||
"type": "Update"
|
||||
}, {
|
||||
"predicate": "messages.stickerSet",
|
||||
"params": [
|
||||
{"name": "refreshTime", "type": "number"}
|
||||
]
|
||||
}]
|
Loading…
x
Reference in New Issue
Block a user