Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/arangodb-client.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion src/HandlesJson.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Http/HttpClientConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<array<mixed>|string|numeric|bool|null>
Expand Down
2 changes: 1 addition & 1 deletion tests/ArangoClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function testGetConfig()
'username' => 'root',
'password' => null,
'database' => $this->testDatabaseName,
'responseSizeDecoderSwitch' => 1048576,
'jsonStreamDecoderThreshold' => 1048576,
];

$config = $this->arangoClient->getConfig();
Expand Down