diff --git a/docs/arangodb-client.md b/docs/arangodb-client.md index fe1e293..12cafe6 100644 --- a/docs/arangodb-client.md +++ b/docs/arangodb-client.md @@ -13,7 +13,7 @@ Upon creation, you can alter the default configuration of the client. The follow * username = null * password = null * database = '_system' -* responseSizeDecoderSwitch = 1 * 1024 * 1024 +* jsonStreamDecoderThreshold = 1 * 1024 * 1024 ``` $config = [ @@ -31,7 +31,7 @@ JSON response decoding is normally done by the default json_decode method. This is optimized for speed and can take a large amount of memory; up to ~ 20x of the JSON size. Therefor we use halaxa/json-machine to stream decode for responses larger than 1MB. -You can alter this cutoff by setting the `responseSizeDecoderSwitch` to a different size in **Bytes**. +You can alter this cutoff by setting the `jsonStreamDecoderThreshold` to a different size in **Bytes**. This removed any memory issues at the cost of speed. diff --git a/src/HandlesJson.php b/src/HandlesJson.php index 65a299f..cbba428 100644 --- a/src/HandlesJson.php +++ b/src/HandlesJson.php @@ -38,7 +38,7 @@ public function jsonEncode(mixed $data): string protected function decodeJsonResponse(ResponseInterface $response): stdClass { $contentLength = $response->getHeaderLine('Content-Length'); - $sizeSwitch = $this->getConfig('responseSizeDecoderSwitch'); + $sizeSwitch = $this->getConfig('jsonStreamDecoderThreshold'); if ($contentLength < $sizeSwitch) { return json_decode($response->getBody()->getContents(), false, 512, JSON_THROW_ON_ERROR); } diff --git a/src/Http/HttpClientConfig.php b/src/Http/HttpClientConfig.php index 6197e3f..b40d806 100644 --- a/src/Http/HttpClientConfig.php +++ b/src/Http/HttpClientConfig.php @@ -40,11 +40,11 @@ class HttpClientConfig extends DataTransferObject /** * Small responses are decoded with json_decode. This is fast but memory intensive. * Large responses are decoded with Halaxa/json-machine stream decoder. - * $responseSizeDecoderSwitch is the response length cutoff in bytes which determines which decoder is used. + * $jsonStreamDecoderThreshold is the response length cutoff in bytes which determines which decoder is used. * * @var int */ - public int $responseSizeDecoderSwitch = 1 * 1024 * 1024; // Default 1 MB + public int $jsonStreamDecoderThreshold = 1 * 1024 * 1024; // Default 1 MB /** * @return array|string|numeric|bool|null> diff --git a/tests/ArangoClientTest.php b/tests/ArangoClientTest.php index 58fd2c2..2f81718 100644 --- a/tests/ArangoClientTest.php +++ b/tests/ArangoClientTest.php @@ -31,7 +31,7 @@ public function testGetConfig() 'username' => 'root', 'password' => null, 'database' => $this->testDatabaseName, - 'responseSizeDecoderSwitch' => 1048576, + 'jsonStreamDecoderThreshold' => 1048576, ]; $config = $this->arangoClient->getConfig();