From 2bbe5af50ba2165b64ae40ce5823be70b6f8d5e3 Mon Sep 17 00:00:00 2001 From: KurimuzonAkuma Date: Thu, 9 Nov 2023 11:43:57 +0300 Subject: [PATCH] Improve speed of stories parsing --- pyrogram/methods/stories/get_all_stories.py | 7 +++++-- pyrogram/methods/stories/get_peer_stories.py | 7 +++++-- pyrogram/methods/stories/get_stories.py | 7 +++++-- pyrogram/methods/stories/get_stories_archive.py | 7 +++++-- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/pyrogram/methods/stories/get_all_stories.py b/pyrogram/methods/stories/get_all_stories.py index d5ea27f9..b0585c0b 100644 --- a/pyrogram/methods/stories/get_all_stories.py +++ b/pyrogram/methods/stories/get_all_stories.py @@ -56,12 +56,15 @@ class GetAllStories: ) ) + users = {i.id: i for i in r.users} + chats = {i.id: i for i in r.chats} + for peer_story in r.peer_stories: for story in peer_story.stories: yield await types.Story._parse( self, story, - {i.id: i for i in r.users}, - {i.id: i for i in r.chats}, + users, + chats, peer_story.peer ) diff --git a/pyrogram/methods/stories/get_peer_stories.py b/pyrogram/methods/stories/get_peer_stories.py index 0b78652d..37fd42ca 100644 --- a/pyrogram/methods/stories/get_peer_stories.py +++ b/pyrogram/methods/stories/get_peer_stories.py @@ -59,11 +59,14 @@ class GetPeerStories: ) ) + users = {i.id: i for i in r.users} + chats = {i.id: i for i in r.chats} + for story in r.stories.stories: yield await types.Story._parse( self, story, - {i.id: i for i in r.users}, - {i.id: i for i in r.chats}, + users, + chats, r.stories.peer ) diff --git a/pyrogram/methods/stories/get_stories.py b/pyrogram/methods/stories/get_stories.py index 64321550..66166307 100644 --- a/pyrogram/methods/stories/get_stories.py +++ b/pyrogram/methods/stories/get_stories.py @@ -69,13 +69,16 @@ class GetStories: stories = [] + users = {i.id: i for i in r.users} + chats = {i.id: i for i in r.chats} + for story in r.stories: stories.append( await types.Story._parse( self, story, - {i.id: i for i in r.users}, - {i.id: i for i in r.chats}, + users, + chats, peer ) ) diff --git a/pyrogram/methods/stories/get_stories_archive.py b/pyrogram/methods/stories/get_stories_archive.py index 0e0c924d..7612af50 100644 --- a/pyrogram/methods/stories/get_stories_archive.py +++ b/pyrogram/methods/stories/get_stories_archive.py @@ -77,12 +77,15 @@ class GetStoriesArchive: last = r.stories[-1] offset_id = last.id + users = {i.id: i for i in r.users} + chats = {i.id: i for i in r.chats} + for story in r.stories: yield await types.Story._parse( self, story, - {i.id: i for i in r.users}, - {i.id: i for i in r.chats}, + users, + chats, peer )