Skip to content
This repository was archived by the owner on Feb 7, 2025. It is now read-only.

Commit 228f7f4

Browse files
authored
Merge pull request #254 from mesilov/248-fast-batch
248 fast batch
2 parents 83f11ca + 87b9f18 commit 228f7f4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+2209
-349
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: "Integration tests"
2+
3+
on:
4+
push:
5+
branches:
6+
- 'master'
7+
- 'dev'
8+
- '2.x'
9+
paths:
10+
- 'src/**'
11+
- 'tests/**'
12+
13+
env:
14+
COMPOSER_FLAGS: "--ansi --no-interaction --no-progress --prefer-dist"
15+
BITRIX24_PHP_SDK_PLAYGROUND_WEBHOOK: ${{ secrets.BITRIX24_PHP_SDK_PLAYGROUND_WEBHOOK }}
16+
jobs:
17+
tests:
18+
name: "Integration tests"
19+
20+
runs-on: ubuntu-latest
21+
22+
strategy:
23+
matrix:
24+
php-version:
25+
- "7.4"
26+
dependencies: [ highest ]
27+
28+
steps:
29+
- name: "Checkout"
30+
uses: "actions/checkout@v2"
31+
32+
- name: "Install PHP"
33+
uses: "shivammathur/setup-php@v2"
34+
with:
35+
coverage: "none"
36+
php-version: "${{ matrix.php-version }}"
37+
38+
- name: "Install dependencies"
39+
run: |
40+
composer update ${{ env.COMPOSER_FLAGS }}
41+
42+
- name: "run unit tests"
43+
run: "composer phpunit-run-integration-tests"

CHANGELOG.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,31 @@
11
# bitrix24-php-sdk change log
22

3+
## 2.0-alpha.6 — 20.01.2021
4+
5+
### Added
6+
7+
* add «fast» batch-query without counting elements in result
8+
recordset [Добавить поддержку выгрузки большого количества данных без подсчёта элементов (-1](https://github.com/mesilov/bitrix24-php-sdk/issues/248)
9+
* add method `Core\Batch::deleteEntityItems` for delete items in batch mode and integration test
10+
* add integration test for read strategy `FilterWithBatchWithoutCountOrderTest`
11+
* add type check in method `Core\Batch::deleteEntityItems` - only integer id allowed
12+
* add interface `Core\Contracts\DeletedItemResultInterface`
13+
* add in scope «CRM» `Services\CRM\Deal\Service\Batch::delete` batch delete deals
14+
* add `symfony/stopwatch` component for integration tests
15+
* add `/Infrastructure/HttpClient/TransportLayer/NetworkTimingsParser` for parse `curl_info` network data structures for debug logs
16+
in `Bitrix24\SDK\Core\Response::__destruct()`
17+
* add `/Infrastructure/HttpClient/TransportLayer/ResponseInfoParser` for parse `bitrix24_rest_api` timing info for debug logs
18+
in `Bitrix24\SDK\Core\Response::__destruct()`
19+
* add `Bitrix24\SDK\Core\BulkItemsReader` for data-intensive applications for bulk export data from Bitrix24, read strategies located in
20+
folder `ReadStrategies`, in services read model **must** use most effective read strategy.
21+
22+
### Changed
23+
24+
* switch `symfony/http-client` to `5.4.*` version requirement.
25+
* switch `symfony/http-client-contracts` to `^2.5` version requirement.
26+
* switch `symfony/event-dispatcher` to `5.4.*` version requirement.
27+
* switch `ramsey/uuid` to `^4.2.3` version requirement.
28+
329
## 2.0-alpha.5 – 28.11.2021
430

531
### Added
@@ -11,7 +37,7 @@
1137
issue [Добавить сервис по работе с юзерфилдами контакта #231](https://github.com/mesilov/bitrix24-php-sdk/issues/231)
1238
* add method getUserfieldByFieldName for `ContactItemResult`
1339
* add in scope «CRM» DealUserfield service and integration test, see
14-
issue [Добавить сервис по работе с юзерфилдами cделки #232](https://github.com/mesilov/bitrix24-php-sdk/issues/232)
40+
issue [Добавить сервис по работе с юзерфилдами cделки #232](https://github.com/mesilov/bitrix24-php-sdk/issues/232)
1541
* add method getUserfieldByFieldName for `DealItemResult`
1642
* add exception `UserfieldNotFoundException`
1743

README.md

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1-
bitrix24-php-sdk [![Build Status](https://travis-ci.org/mesilov/bitrix24-php-sdk.svg?branch=master)](https://travis-ci.org/mesilov/bitrix24-php-sdk)
1+
bitrix24-php-sdk – Bitrix24 REST API PHP SDK
22
================
33
[![License](https://poser.pugx.org/mesilov/bitrix24-php-sdk/license.svg)](https://packagist.org/packages/mesilov/bitrix24-php-sdk) [![Total Downloads](https://poser.pugx.org/mesilov/bitrix24-php-sdk/downloads.svg)](https://packagist.org/packages/mesilov/bitrix24-php-sdk)
4+
[![Latest Stable Version](https://img.shields.io/packagist/v/mesilov/bitrix24-php-sdk.svg)](https://packagist.org/packages/mesilov/bitrix24-php-sdk)
45

56
A powerful PHP library for the Bitrix24 REST API
7+
8+
### Build status
9+
10+
[![phpstan check](https://github.com/mesilov/bitrix24-php-sdk/actions/workflows/phpstan.yml/badge.svg)](https://github.com/mesilov/bitrix24-php-sdk/actions/workflows/phpstan.yml)
11+
[![phpunit unit-tests status](https://github.com/mesilov/bitrix24-php-sdk/actions/workflows/phpunit.yml/badge.svg)](https://github.com/mesilov/bitrix24-php-sdk/actions/workflows/phpunit.yml)
12+
613
### BITRIX24-PHP-SDK Documentation
714

815
- [Russian](/docs/RU/documentation.md)
@@ -42,23 +49,23 @@ Performance improvements 🚀
4249
### Development principles
4350

4451
- Good developer experience
45-
- auto-completion of methods at the IDE
46-
- typed method call signatures
47-
- typed results of method calls
48-
- helpers for typical operations
52+
- auto-completion of methods at the IDE
53+
- typed method call signatures
54+
- typed results of method calls
55+
- helpers for typical operations
4956
- Good documentation
50-
- documentation on the operation of a specific method containing a link to the official documentation
51-
- documentation for working with the SDK
57+
- documentation on the operation of a specific method containing a link to the official documentation
58+
- documentation for working with the SDK
5259
- Performance first:
53-
- minimal impact on client code
54-
- ability to work with large amounts of data with constant memory consumption
55-
- efficient operation of the API using butch requests
60+
- minimal impact on client code
61+
- ability to work with large amounts of data with constant memory consumption
62+
- efficient operation of the API using butch requests
5663
- Modern technology stack
57-
- based on [Symfony HttpClient](https://symfony.com/doc/current/http_client.html)
58-
- actual PHP versions language features
64+
- based on [Symfony HttpClient](https://symfony.com/doc/current/http_client.html)
65+
- actual PHP versions language features
5966
- Reliable:
60-
- test coverage: unit, integration, contract
61-
- typical examples typical for different modes of operation and they are optimized for memory \ performance
67+
- test coverage: unit, integration, contract
68+
- typical examples typical for different modes of operation and they are optimized for memory \ performance
6269

6370
### Architecture
6471

@@ -107,47 +114,53 @@ Performance improvements 🚀
107114
Add `"mesilov/bitrix24-php-sdk": "2.x"` to `composer.json` of your application. Or clone repo to your project.
108115

109116
### Tests
117+
110118
Tests locate in folder `tests` and we have two test types
111119

112120
#### Unit tests
113-
**Fast**, in-memory tests without a network I\O
114-
For run unit tests you must call in command line
121+
122+
**Fast**, in-memory tests without a network I\O For run unit tests you must call in command line
115123

116124
```shell
117125
composer phpunit-run-unit-test
118126
```
119127

120128
#### Integration tests
129+
121130
**Slow** tests with full lifecycle with your **test** Bitrix24 portal via webhook.
122131

123132
❗️Do not run integration tests with production portals ❗️
124133

125134
For run integration test you must:
135+
126136
1. Create [new Bitrix24 portal](https://www.bitrix24.ru/create.php?p=255670) for development tests
127137
2. Go to left menu, click «Sitemap»
128138
3. Find menu item «Developer resources»
129139
4. Click on menu item «Other»
130140
5. Click on menu item «Inbound webhook»
131141
6. Assign all permisions with webhook and click «save» button
132142
7. Create file `/tests/.env.local` with same settings, see comments in `/tests/.env` file.
143+
133144
```yaml
134145
APP_ENV=dev
135146
BITRIX24_WEBHOOK=https:// your portal webhook url
136147
INTEGRATION_TEST_LOG_LEVEL=500
137148
```
149+
138150
8. call in command line
139151

140152
```shell
141153
composer composer phpunit-run-integration-tests
142154
```
143155

144156
#### PHP Static Analysis Tool – phpstan
157+
145158
Call in command line
159+
146160
```shell
147161
composer phpstan-analyse
148162
```
149163

150-
151164
### Submitting bugs and feature requests
152165

153166
Bugs and feature request are tracked on [GitHub](https://github.com/mesilov/bitrix24-php-sdk/issues)

composer.json

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,19 @@
2222
"ext-curl": "*",
2323
"psr/log": "1.1.3",
2424
"fig/http-message-util": "1.1.*",
25-
"symfony/http-client": "5.3.*",
26-
"symfony/http-client-contracts": "^2.4",
27-
"symfony/event-dispatcher": "5.3.*",
28-
"ramsey/uuid": "^4.0"
25+
"symfony/http-client": "5.4.*",
26+
"symfony/http-client-contracts": "^2.5",
27+
"symfony/event-dispatcher": "5.4.*",
28+
"ramsey/uuid": "^4.2.3"
2929
},
3030
"require-dev": {
3131
"monolog/monolog": "2.1.*",
32-
"symfony/console": "5.3.*",
33-
"symfony/dotenv": "5.3.*",
34-
"symfony/debug-bundle": "5.3.*",
32+
"symfony/console": "5.4.*",
33+
"symfony/dotenv": "5.4.*",
34+
"symfony/debug-bundle": "5.4.*",
3535
"phpstan/phpstan": "1.1.*",
3636
"phpunit/phpunit": "9.5.*",
37+
"symfony/stopwatch": "5.4.*",
3738
"roave/security-advisories": "dev-master"
3839
},
3940
"autoload": {
@@ -55,7 +56,7 @@
5556
"phpunit --testsuite integration_tests"
5657
],
5758
"phpstan-analyse": [
58-
"vendor/bin/phpstan analyse"
59+
"vendor/bin/phpstan analyse --memory-limit 1G"
5960
]
6061
}
6162
}

docs/RU/Core/Batch/batch-read-mode.md

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -88,22 +88,21 @@ Help:
8888
8989
Режим | отдельные поля | вся сущность | вся сущность + UF_*
9090
--- | --- | --- | ---
91-
сортировка, подсчёт количества элементов в выборке | 0.1724 | 1.9875 | 2.3136
92-
сортировка, без подсчёта количества элементов в выборке | 0.1173 | 1.3289 | 1.476
93-
сортировка по умолчанию, подсчёт количества элементов в выборке | 0.0936 | 0.926 | 1.0272
94-
сортировка по умолчанию, без подсчёта количества элементов в выборке | 0.0362 | 0.2701 | 0.2688
91+
сортировка, подсчёт количества элементов в выборке | 0.3786 | 2.6767 | 3.1891
92+
сортировка, без подсчёта количества элементов в выборке | 0.3125 | 1.745 | 1.956
93+
сортировка по умолчанию, подсчёт количества элементов в выборке | 0.3129 | 1.3176 | 1.523
94+
сортировка по умолчанию, без подсчёта количества элементов в выборке | **0.2241** | **0.458** | **0.4858**
9595
96-
### Чтение 6000 элементов отдельные поля \ вся сущность \ вся сущность + пользовательские поля
96+
### Чтение 2700 элементов в batch-режиме отдельные поля \ вся сущность \ вся сущность + пользовательские поля
9797
98-
В данном примере используются batch-запросы, которые выбирают данные чанками по 2500, 2500 и 1000 элементов. Сами батч запросы реализуются
99-
сервисом `Bitrix24\SDK\Core\Batch` Время — секунды, округление до 4 знаков.
98+
Сами запросы строятся сервисом `Bitrix24\SDK\Core\Batch` Время — секунды, округление до 4 знаков.
10099
101100
Режим | отдельные поля | вся сущность | вся сущность + UF_*
102101
--- | --- | --- | ---
103-
сортировка, подсчёт количества элементов в выборке | 17.8018 | 239.8081 | 274.9921
104-
сортировка, без подсчёта количества элементов в выборке | **not implemented** | **not implemented** | **not implemented**
105-
сортировка по умолчанию, подсчёт количества элементов в выборке | 8.2121 | 110.0122 | 125.7331
106-
сортировка по умолчанию, без подсчёта количества элементов в выборке | **not implemented** | **not implemented** | **not implemented**
102+
сортировка, подсчёт количества элементов в выборке | 19.7924 | 131.3065 | 168.753
103+
сортировка, без подсчёта количества элементов в выборке | 27.0083 | **30.8689** | **32.6827**
104+
сортировка по умолчанию, подсчёт количества элементов в выборке | **14.3636** | 70.5149 | 79.5987
105+
сортировка по умолчанию, без подсчёта количества элементов в выборке | 26.5045 | 31.1381 | 33.8329
107106
108107
## Подготовка тестового окружения
109108
@@ -115,8 +114,8 @@ Help:
115114
1. В текущей версии статьи в портале было 100к элементов в сущности, эта ситуация характерна для небольшого количества порталов
116115
2. Замеры производились когда на портале отсутствовала операционная нагрузка характерная для рабочего дня
117116
3. По возможности старайтесь избегать выборки всех данных
118-
4. Сортировка данных при больших выборках тоже слишком дорогая операция
119-
5. В roadmap SDK будет добавлена задача на поддержку batch-запросов в режиме «отключенный подсчёт количества» элементов, сейчас там
120-
указано **not implemented**
121-
6. Замеры будут проведены для кейсов от 10к до 200к элементов с шагом 10к элементов.
122-
7. В коробочной версии Битрикс24 показатели могут существенно отличаться
117+
4. Сортировка данных при больших выборках тоже дорогая операция
118+
5. Имеет смысл сделать замеры при изменении количества элементов на портале 10к до 500к элементов с шагом 20к элементов.
119+
6. В коробочной версии Битрикс24 показатели могут существенно отличаться
120+
7. В SDK выделен отдельный сервис `Core\BulkItemsReader` который реализует более эффективные стратегии чем простой batch, на текущий момент
121+
оптимизация скорости чтения данных не производилась, используется стратегия «батч без подсчёта количества элементов»

phpstan.neon.dist

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@ parameters:
22
level: 5
33
paths:
44
- src/
5-
# - tests/
65
bootstrapFiles:
76
- tests/bootstrap.php

src/Core/ApiClient.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function __construct(Credentials\Credentials $credentials, HttpClientInte
4848
}
4949

5050
/**
51-
* @return array
51+
* @return array<string,string>
5252
*/
5353
protected function getDefaultHeaders(): array
5454
{
@@ -112,18 +112,19 @@ public function getNewAccessToken(): RenewedAccessToken
112112
}
113113

114114
/**
115-
* @param string $apiMethod
116-
* @param array $parameters
115+
* @param string $apiMethod
116+
* @param array<mixed> $parameters
117117
*
118118
* @return ResponseInterface
119119
* @throws TransportExceptionInterface
120120
* @throws InvalidArgumentException
121121
*/
122122
public function getResponse(string $apiMethod, array $parameters = []): ResponseInterface
123123
{
124-
$this->logger->debug(
125-
sprintf('getResponse.start %s', $apiMethod),
124+
$this->logger->info(
125+
'getResponse.start',
126126
[
127+
'apiMethod' => $apiMethod,
127128
'domainUrl' => $this->credentials->getDomainUrl(),
128129
'parameters' => $parameters,
129130
]
@@ -147,9 +148,10 @@ public function getResponse(string $apiMethod, array $parameters = []): Response
147148
];
148149
$response = $this->client->request($method, $url, $requestOptions);
149150

150-
$this->logger->debug(
151-
sprintf('getResponse.end [%s]', $apiMethod),
151+
$this->logger->info(
152+
'getResponse.end',
152153
[
154+
'apiMethod' => $apiMethod,
153155
'responseInfo' => $response->getInfo(),
154156
]
155157
);

src/Core/ApiLevelErrorHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function __construct(LoggerInterface $logger)
3333
}
3434

3535
/**
36-
* @param array $responseBody
36+
* @param array<string,string> $responseBody
3737
*
3838
* @throws QueryLimitExceededException
3939
* @throws BaseException

0 commit comments

Comments
 (0)