diff --git a/src/Symfony/Component/Lock/Store/MongoDbStore.php b/src/Symfony/Component/Lock/Store/MongoDbStore.php index 296c68be1072a..34c740a6685c9 100644 --- a/src/Symfony/Component/Lock/Store/MongoDbStore.php +++ b/src/Symfony/Component/Lock/Store/MongoDbStore.php @@ -14,8 +14,8 @@ use MongoDB\BSON\UTCDateTime; use MongoDB\Client; use MongoDB\Collection; -use MongoDB\Driver\Command; use MongoDB\Driver\Exception\WriteException; +use MongoDB\Driver\ReadPreference; use MongoDB\Exception\DriverRuntimeException; use MongoDB\Exception\InvalidArgumentException as MongoInvalidArgumentException; use MongoDB\Exception\UnsupportedException; @@ -54,8 +54,6 @@ class MongoDbStore implements BlockingStoreInterface private $options; private $initialTtl; - private $databaseVersion; - use ExpiringStoreTrait; /** @@ -87,8 +85,8 @@ class MongoDbStore implements BlockingStoreInterface * to 0.0 and optionally leverage * self::createTtlIndex(int $expireAfterSeconds = 0). * - * writeConcern, readConcern and readPreference are not specified by - * MongoDbStore meaning the collection's settings will take effect. + * writeConcern and readConcern are not specified by MongoDbStore meaning the connection's settings will take effect. + * readPreference is primary for all queries. * @see https://docs.mongodb.com/manual/applications/replication/ */ public function __construct($mongo, array $options = [], float $initialTtl = 300.0) @@ -262,6 +260,8 @@ public function exists(Key $key): bool 'expires_at' => [ '$gt' => $this->createMongoDateTime(microtime(true)), ], + ], [ + 'readPreference' => new ReadPreference(\defined(ReadPreference::PRIMARY) ? ReadPreference::PRIMARY : ReadPreference::RP_PRIMARY), ]); } @@ -315,25 +315,6 @@ private function isDuplicateKeyException(WriteException $e): bool return 11000 === $code; } - private function getDatabaseVersion(): string - { - if (null !== $this->databaseVersion) { - return $this->databaseVersion; - } - - $command = new Command([ - 'buildinfo' => 1, - ]); - $cursor = $this->getCollection()->getManager()->executeReadCommand( - $this->getCollection()->getDatabaseName(), - $command - ); - $buildInfo = $cursor->toArray()[0]; - $this->databaseVersion = $buildInfo->version; - - return $this->databaseVersion; - } - private function getCollection(): Collection { if (null !== $this->collection) { pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy