Skip to content

Commit 91f27f2

Browse files
committed
Huge "KVClient::getTree" performance update
1 parent 45bfb50 commit 91f27f2

File tree

7 files changed

+10
-16
lines changed

7 files changed

+10
-16
lines changed

src/Agent/AgentClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
*/
1818

1919
use DCarbone\PHPConsulAPI\AbstractApiClient;
20-
use DCarbone\PHPConsulAPI\Hydrator;
2120
use DCarbone\PHPConsulAPI\HttpRequest;
21+
use DCarbone\PHPConsulAPI\Hydrator;
2222

2323
/**
2424
* Class AgentClient

src/Agent/AgentService.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
use DCarbone\PHPConsulAPI\AbstractDefinedCollection;
2020
use DCarbone\PHPConsulAPI\AbstractObjectModel;
21-
use DCarbone\PHPConsulAPI\TaggedInterface;
2221

2322
/**
2423
* Class AgentService

src/Catalog/CatalogClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
*/
1818

1919
use DCarbone\PHPConsulAPI\AbstractApiClient;
20+
use DCarbone\PHPConsulAPI\HttpRequest;
2021
use DCarbone\PHPConsulAPI\Hydrator;
2122
use DCarbone\PHPConsulAPI\QueryOptions;
22-
use DCarbone\PHPConsulAPI\HttpRequest;
2323
use DCarbone\PHPConsulAPI\WriteOptions;
2424

2525
/**

src/Coordinate/CoordinateClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
*/
1818

1919
use DCarbone\PHPConsulAPI\AbstractApiClient;
20+
use DCarbone\PHPConsulAPI\HttpRequest;
2021
use DCarbone\PHPConsulAPI\Hydrator;
2122
use DCarbone\PHPConsulAPI\QueryOptions;
22-
use DCarbone\PHPConsulAPI\HttpRequest;
2323

2424
/**
2525
* Class CoordinateClient

src/Event/EventClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
*/
1818

1919
use DCarbone\PHPConsulAPI\AbstractApiClient;
20+
use DCarbone\PHPConsulAPI\HttpRequest;
2021
use DCarbone\PHPConsulAPI\Hydrator;
2122
use DCarbone\PHPConsulAPI\QueryOptions;
22-
use DCarbone\PHPConsulAPI\HttpRequest;
2323
use DCarbone\PHPConsulAPI\WriteOptions;
2424

2525
/**

src/Health/HealthClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818

1919
use DCarbone\PHPConsulAPI\AbstractApiClient;
2020
use DCarbone\PHPConsulAPI\Error;
21+
use DCarbone\PHPConsulAPI\HttpRequest;
2122
use DCarbone\PHPConsulAPI\Hydrator;
2223
use DCarbone\PHPConsulAPI\QueryOptions;
23-
use DCarbone\PHPConsulAPI\HttpRequest;
2424

2525
/**
2626
* Class HealthClient

src/KV/KVClient.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818

1919
use DCarbone\PHPConsulAPI\AbstractApiClient;
2020
use DCarbone\PHPConsulAPI\Error;
21+
use DCarbone\PHPConsulAPI\HttpRequest;
2122
use DCarbone\PHPConsulAPI\Hydrator;
2223
use DCarbone\PHPConsulAPI\QueryOptions;
23-
use DCarbone\PHPConsulAPI\HttpRequest;
2424
use DCarbone\PHPConsulAPI\WriteOptions;
2525

2626
/**
@@ -201,22 +201,21 @@ public function delete($key, WriteOptions $writeOptions = null)
201201
*/
202202
public function tree($prefix = null, QueryOptions $queryOptions = null)
203203
{
204-
list($keys, $_, $err) = $this->keys($prefix, $queryOptions);
204+
list($valueList, $_, $err) = $this->valueList($prefix, $queryOptions);
205205

206206
if (null !== $err)
207207
return [null, $err];
208208

209209
$treeHierarchy = array();
210-
foreach($keys as $path)
210+
foreach($valueList as $path=>$kvp)
211211
{
212212
$slashPos = strpos($path, '/');
213213
if (false === $slashPos)
214214
{
215-
list($kv, $_, $err) = $this->get($path, $queryOptions);
216215
if (null !== $err)
217216
return [null, $err];
218217

219-
$treeHierarchy[$path] = $kv;
218+
$treeHierarchy[$path] = $kvp;
220219
continue;
221220
}
222221

@@ -233,11 +232,7 @@ public function tree($prefix = null, QueryOptions $queryOptions = null)
233232
// We've arrived at an actual key
234233
else
235234
{
236-
list($kv, $_, $err) = $this->get($path, $queryOptions);
237-
if (null !== $err)
238-
return [null, $err];
239-
240-
$treeHierarchy[$root][$path] = $kv;
235+
$treeHierarchy[$root][$path] = $kvp;
241236
}
242237
}
243238
return [$treeHierarchy, null];

0 commit comments

Comments
 (0)