13
13
14
14
namespace Laudis \Neo4j \Neo4j ;
15
15
16
- use function array_unique ;
17
-
18
16
use Bolt \error \ConnectException ;
19
17
20
18
use function count ;
25
23
use function implode ;
26
24
27
25
use Laudis \Neo4j \Bolt \BoltConnection ;
28
- use Laudis \Neo4j \Bolt \Connection ;
29
26
use Laudis \Neo4j \Bolt \ConnectionPool ;
30
27
use Laudis \Neo4j \BoltFactory ;
31
28
use Laudis \Neo4j \Common \Cache ;
@@ -127,7 +124,7 @@ public function acquire(SessionConfiguration $config): Generator
127
124
{
128
125
$ key = $ this ->createKey ($ this ->data , $ config );
129
126
130
- /** @var RoutingTable|null */
127
+ /** @var RoutingTable|null $table */
131
128
$ table = $ this ->cache ->get ($ key );
132
129
$ triedAddresses = [];
133
130
@@ -164,7 +161,7 @@ public function acquire(SessionConfiguration $config): Generator
164
161
throw new RuntimeException (sprintf ('Cannot connect to host: "%s". Hosts tried: "%s" ' , $ this ->data ->getUri ()->getHost (), implode ('", " ' , $ triedAddresses )), previous: $ latestError );
165
162
}
166
163
167
- $ server = $ this ->getNextServer ($ table , $ config ->getAccessMode ()) ?? $ this -> data -> getUri () ;
164
+ $ server = $ this ->getNextServer ($ table , $ config ->getAccessMode ());
168
165
169
166
if ($ server ->getScheme () === '' ) {
170
167
$ server = $ server ->withScheme ($ this ->data ->getUri ()->getScheme ());
@@ -181,13 +178,8 @@ public function getLogger(): ?Neo4jLogger
181
178
/**
182
179
* @throws Exception
183
180
*/
184
- private function getNextServer (RoutingTable $ table , AccessMode $ mode ): ? Uri
181
+ private function getNextServer (RoutingTable $ table , AccessMode $ mode ): Uri
185
182
{
186
- $ servers = array_unique ($ table ->getWithRole ());
187
- if (count ($ servers ) === 1 ) {
188
- return null ;
189
- }
190
-
191
183
if (AccessMode::WRITE () === $ mode ) {
192
184
$ servers = $ table ->getWithRole (RoutingRoles::LEADER ());
193
185
} else {
@@ -233,7 +225,7 @@ private function createKey(ConnectionRequestData $data, ?SessionConfiguration $c
233
225
[
234
226
$ data ->getUserAgent (),
235
227
$ uri ->getHost (),
236
- $ config ? $ config ->getDatabase () : null ,
228
+ $ config? ->getDatabase(),
237
229
$ uri ->getPort () ?? '7687 ' ,
238
230
]
239
231
)
0 commit comments