From 4927c47442d22020ec14197433c1a105385de527 Mon Sep 17 00:00:00 2001 From: mhh Date: Fri, 6 Oct 2023 19:19:38 +0200 Subject: [PATCH] prevent unnecessary .as_http_params() call --- src/aleph/sdk/client/client.py | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/aleph/sdk/client/client.py b/src/aleph/sdk/client/client.py index 8e96645a..ce5c43db 100644 --- a/src/aleph/sdk/client/client.py +++ b/src/aleph/sdk/client/client.py @@ -284,10 +284,14 @@ async def get_posts( ) if not post_filter: - post_filter = PostFilter() - params = post_filter.as_http_params() - params["page"] = str(page) - params["pagination"] = str(page_size) + params = { + "page": str(page), + "pagination": str(page_size), + } + else: + params = post_filter.as_http_params() + params["page"] = str(page) + params["pagination"] = str(page_size) async with self.http_session.get("/api/v0/posts.json", params=params) as resp: resp.raise_for_status() @@ -408,10 +412,15 @@ async def get_messages( ) if not message_filter: - message_filter = MessageFilter() - params = message_filter.as_http_params() - params["page"] = str(page) - params["pagination"] = str(page_size) + params = { + "page": str(page), + "pagination": str(page_size), + } + else: + params = message_filter.as_http_params() + params["page"] = str(page) + params["pagination"] = str(page_size) + async with self.http_session.get( "/api/v0/messages.json", params=params ) as resp: @@ -479,8 +488,7 @@ async def watch_messages( self, message_filter: Optional[MessageFilter] = None, ) -> AsyncIterable[AlephMessage]: - if not message_filter: - message_filter = MessageFilter() + message_filter = message_filter or MessageFilter() params = message_filter.as_http_params() async with self.http_session.ws_connect(