From 8906953b38fab98703d2c88283cf0ce5eaa44036 Mon Sep 17 00:00:00 2001 From: Alexey Leshchenko Date: Sun, 24 Mar 2024 00:01:17 +0300 Subject: [PATCH 1/4] =?UTF-8?q?=D0=A2=D0=B5=D0=BF=D0=B5=D1=80=D1=8C=20?= =?UTF-8?q?=D0=BC=D0=BE=D0=B6=D0=BD=D0=BE=20=D0=B8=D1=81=D0=BF=D0=BE=D0=BB?= =?UTF-8?q?=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D1=82=D1=8C=20'limit'=20c=20`get?= =?UTF-8?q?=5Fall()`,=20=D0=BD=D0=BE=20=D0=B2=D1=8B=D0=B4=D0=B0=D0=B5?= =?UTF-8?q?=D1=82=D1=81=D1=8F=20=D0=BF=D1=80=D0=B5=D0=B4=D1=83=D0=BF=D1=80?= =?UTF-8?q?=D0=B5=D0=B6=D0=B4=D0=B5=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- API.md | 2 +- fast_bitrix24/user_request.py | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/API.md b/API.md index ba4ac3f..6060366 100644 --- a/API.md +++ b/API.md @@ -31,7 +31,7 @@ #### Параметры * `method: str` - метод REST API для запроса к серверу. -* `params: dict` - параметры для передачи методу. Используется именно тот формат, который указан в документации к REST API Битрикс24. `get_all()` не поддерживает параметры `start`, `limit` и `order`. +* `params: dict` - параметры для передачи методу. Используется именно тот формат, который указан в документации к REST API Битрикс24. `get_all()` не поддерживает параметры `start` и `order`. Возвращает полный список сущностей, имеющихся на сервере, согласно заданным методу и параметрам. diff --git a/fast_bitrix24/user_request.py b/fast_bitrix24/user_request.py index eba82d4..8d992c0 100644 --- a/fast_bitrix24/user_request.py +++ b/fast_bitrix24/user_request.py @@ -113,8 +113,8 @@ async def run(self): class GetAllUserRequest(UserRequestAbstract): @icontract.require( lambda self: not self.st_params - or set(self.st_params.keys()).isdisjoint({"START", "LIMIT", "ORDER"}), - "get_all() doesn't support parameters " "'start', 'limit' or 'order'", + or set(self.st_params.keys()).isdisjoint({"START", "ORDER"}), + "get_all() doesn't support parameters 'start' or 'order'", ) @icontract.require( lambda self: not self.st_method.startswith("tasks.elapseditem."), @@ -131,6 +131,13 @@ def check_special_limitations(self): stacklevel=get_warning_stack_level(TOP_MOST_LIBRARY_MODULES), ) + if "LIMIT" in self.st_params: + warnings.warn( + "Bitrix servers don't seem to support the 'LIMIT' parameter.", + UserWarning, + stacklevel=get_warning_stack_level(TOP_MOST_LIBRARY_MODULES), + ) + return True async def run(self): From 8145bf68e01ab55a4d2d0effa8289923824f3896 Mon Sep 17 00:00:00 2001 From: Alexey Leshchenko Date: Sun, 24 Mar 2024 01:19:47 +0300 Subject: [PATCH 2/4] =?UTF-8?q?=D0=92=D0=BD=D1=83=D1=82=D1=80=D0=B8=20?= =?UTF-8?q?=D0=B1=D0=B0=D1=82=D1=87=D0=B5=D0=B9=20=D1=83=D1=87=D0=B8=D1=82?= =?UTF-8?q?=D1=8B=D0=B2=D0=B0=D1=82=D1=8C=20=D0=B2=D1=80=D0=B5=D0=BC=D1=8F?= =?UTF-8?q?=20=D0=B2=D1=8B=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F?= =?UTF-8?q?=20=D0=B4=D0=BB=D1=8F=20=D0=BA=D0=B0=D0=B6=D0=B4=D0=BE=D0=B3?= =?UTF-8?q?=D0=BE=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=D0=B0=20=D1=80=D0=B0?= =?UTF-8?q?=D0=B7=D0=B4=D0=B5=D0=BB=D1=8C=D0=BD=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fast_bitrix24/srh.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/fast_bitrix24/srh.py b/fast_bitrix24/srh.py index b463af3..0e936c6 100644 --- a/fast_bitrix24/srh.py +++ b/fast_bitrix24/srh.py @@ -163,9 +163,7 @@ async def request_attempt(self, method, params=None) -> dict: logger.debug("Response: %s", json) - request_run_time = json["time"]["operating"] - self.method_throttlers[method].add_request_record(request_run_time) - self.leaky_bucket_throttler.add_request_record() + self.add_throttler_records(method, params, json) return json @@ -175,6 +173,18 @@ async def request_attempt(self, method, params=None) -> dict: raise + def add_throttler_records(self, method, params: dict, json: dict): + if "result_time" in json: + for cmd_name, cmd_url in params["cmd"].items(): + item_method = cmd_url.split("?")[0] + item_time = json["result_time"][cmd_name] + self.method_throttlers[item_method].add_request_record(item_time) + else: + request_run_time = json["time"]["operating"] + self.method_throttlers[method].add_request_record(request_run_time) + + self.leaky_bucket_throttler.add_request_record() + def success(self): """Увеличить счетчик удачных попыток.""" From 6462b68ae05223b733f0214b86515497bb0a3084 Mon Sep 17 00:00:00 2001 From: Alexey Leshchenko Date: Sun, 24 Mar 2024 01:20:49 +0300 Subject: [PATCH 3/4] =?UTF-8?q?=D0=9F=D1=80=D0=B5=D0=B4=D1=83=D0=BF=D1=80?= =?UTF-8?q?=D0=B5=D0=B6=D0=B4=D0=B5=D0=BD=D0=B8=D0=B5,=20=D0=B5=D1=81?= =?UTF-8?q?=D0=BB=D0=B8=20=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D1=82=D0=B5=D0=BB=D1=8C=20=D0=B7=D0=B0=D0=B3=D1=80=D1=83=D0=B6?= =?UTF-8?q?=D0=B0=D0=B5=D1=82=20=D0=B2=D1=81=D0=B5=20=D0=BF=D0=BE=D0=BB?= =?UTF-8?q?=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fast_bitrix24/user_request.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/fast_bitrix24/user_request.py b/fast_bitrix24/user_request.py index 8d992c0..f002082 100644 --- a/fast_bitrix24/user_request.py +++ b/fast_bitrix24/user_request.py @@ -138,6 +138,14 @@ def check_special_limitations(self): stacklevel=get_warning_stack_level(TOP_MOST_LIBRARY_MODULES), ) + if "SELECT" in self.st_params and "*" in self.st_params["SELECT"]: + warnings.warn( + "You are selecting all fields. Beware that this is time-consuming and " + "may lead to penalties from the Bitrix server.", + UserWarning, + stacklevel=get_warning_stack_level(TOP_MOST_LIBRARY_MODULES), + ) + return True async def run(self): From 65ca05eba6f75e059542c4adb2cf95cea7bb1faf Mon Sep 17 00:00:00 2001 From: Alexey Leshchenko Date: Sun, 24 Mar 2024 01:24:53 +0300 Subject: [PATCH 4/4] Fix --- fast_bitrix24/user_request.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/fast_bitrix24/user_request.py b/fast_bitrix24/user_request.py index f002082..e3a8bce 100644 --- a/fast_bitrix24/user_request.py +++ b/fast_bitrix24/user_request.py @@ -131,14 +131,18 @@ def check_special_limitations(self): stacklevel=get_warning_stack_level(TOP_MOST_LIBRARY_MODULES), ) - if "LIMIT" in self.st_params: + if self.st_params and "LIMIT" in self.st_params: warnings.warn( "Bitrix servers don't seem to support the 'LIMIT' parameter.", UserWarning, stacklevel=get_warning_stack_level(TOP_MOST_LIBRARY_MODULES), ) - if "SELECT" in self.st_params and "*" in self.st_params["SELECT"]: + if ( + self.st_params + and "SELECT" in self.st_params + and "*" in self.st_params["SELECT"] + ): warnings.warn( "You are selecting all fields. Beware that this is time-consuming and " "may lead to penalties from the Bitrix server.",