Skip to content

Commit

Permalink
Changed config name from responseSizeDecoderSwitch to jsonStreamDecod…
Browse files Browse the repository at this point in the history
…erThreshold (#32)
  • Loading branch information
LaravelFreelancerNL authored Oct 7, 2024
1 parent 5ddafca commit 44d8598
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
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

0 comments on commit 44d8598

Please sign in to comment.