diff --git a/pyrogram/types/messages_and_media/sticker.py b/pyrogram/types/messages_and_media/sticker.py index 87dd2f7e..5b63a2fe 100644 --- a/pyrogram/types/messages_and_media/sticker.py +++ b/pyrogram/types/messages_and_media/sticker.py @@ -18,8 +18,6 @@ from typing import List -from async_lru import alru_cache - import pyrogram from pyrogram import raw from pyrogram import types @@ -105,18 +103,35 @@ class Sticker(Object): self.thumbs = thumbs # self.mask_position = mask_position + cache = {} + @staticmethod - @alru_cache(maxsize=256) async def _get_sticker_set_name(send, input_sticker_set_id): try: - return (await send( + set_id = input_sticker_set_id[0] + set_access_hash = input_sticker_set_id[1] + + name = Sticker.cache.get((set_id, set_access_hash), None) + + if name is not None: + return name + + name = (await send( raw.functions.messages.GetStickerSet( stickerset=raw.types.InputStickerSetID( - id=input_sticker_set_id[0], - access_hash=input_sticker_set_id[1] + id=set_id, + access_hash=set_access_hash ) ) )).set.short_name + + Sticker.cache[(set_id, set_access_hash)] = name + + if len(Sticker.cache) > 250: + for i in range(50): + Sticker.cache.pop(next(iter(Sticker.cache))) + + return name except StickersetInvalid: return None