From 6efd01937fa89441d381b4ad98b839268ca2d149 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 6 Oct 2021 17:12:49 +0200 Subject: [PATCH] Fix issues with Python 3.10 (#766) --- pyrogram/types/messages_and_media/sticker.py | 27 +++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) 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