From baba8806b610e4ba6e1f60dd3ae7a24c027be9e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Thu, 25 May 2023 16:18:39 +0200 Subject: [PATCH] Send readConcern but not writeConcern to explain commands --- psalm-baseline.xml | 12 ++++++++---- src/Operation/Aggregate.php | 9 ++++++++- src/Operation/Count.php | 9 ++++++++- src/Operation/Delete.php | 8 +------- src/Operation/Distinct.php | 9 ++++++++- src/Operation/Find.php | 9 ++++++++- src/Operation/Update.php | 4 ---- 7 files changed, 41 insertions(+), 19 deletions(-) diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 583e0c94d..1d76ad95b 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -286,10 +286,11 @@ $this->options['typeMap'] $this->options['typeMap'] - + $cmdOptions['maxAwaitTimeMS'] $cmd[$option] $cmd['hint'] + $cmd['readConcern'] $options[$option] $options['writeConcern'] @@ -383,9 +384,10 @@ ! is_array($filter) && ! is_object($filter) - + $cmd[$option] $cmd['hint'] + $cmd['readConcern'] $options['readConcern'] $options['readPreference'] $options['session'] @@ -468,8 +470,9 @@ $this->options['typeMap'] - + $cmd[$option] + $cmd['readConcern'] $options['readConcern'] $options['readPreference'] $options['session'] @@ -534,7 +537,8 @@ $options['modifiers'][$modifier[1]] - + + $cmd['readConcern'] $options[$modifier[0]] $options[$option] $options['readPreference'] diff --git a/src/Operation/Aggregate.php b/src/Operation/Aggregate.php index 040e3c9c9..5b278cdd2 100644 --- a/src/Operation/Aggregate.php +++ b/src/Operation/Aggregate.php @@ -309,7 +309,14 @@ public function execute(Server $server) */ public function getCommandDocument(Server $server) { - return $this->createCommandDocument(); + $cmd = $this->createCommandDocument(); + + // Read concern can change the query plan + if (isset($this->options['readConcern'])) { + $cmd['readConcern'] = $this->options['readConcern']; + } + + return $cmd; } /** diff --git a/src/Operation/Count.php b/src/Operation/Count.php index 7e427313c..251ba900a 100644 --- a/src/Operation/Count.php +++ b/src/Operation/Count.php @@ -173,7 +173,14 @@ public function execute(Server $server) */ public function getCommandDocument(Server $server) { - return $this->createCommandDocument(); + $cmd = $this->createCommandDocument(); + + // Read concern can change the query plan + if (isset($this->options['readConcern'])) { + $cmd['readConcern'] = $this->options['readConcern']; + } + + return $cmd; } /** diff --git a/src/Operation/Delete.php b/src/Operation/Delete.php index 7ca197f7a..129990ac4 100644 --- a/src/Operation/Delete.php +++ b/src/Operation/Delete.php @@ -178,13 +178,7 @@ public function execute(Server $server) */ public function getCommandDocument(Server $server) { - $cmd = ['delete' => $this->collectionName, 'deletes' => [['q' => $this->filter] + $this->createDeleteOptions()]]; - - if (isset($this->options['writeConcern'])) { - $cmd['writeConcern'] = $this->options['writeConcern']; - } - - return $cmd; + return ['delete' => $this->collectionName, 'deletes' => [['q' => $this->filter] + $this->createDeleteOptions()]]; } /** diff --git a/src/Operation/Distinct.php b/src/Operation/Distinct.php index 3c2f93dbd..a249adf71 100644 --- a/src/Operation/Distinct.php +++ b/src/Operation/Distinct.php @@ -166,7 +166,14 @@ public function execute(Server $server) */ public function getCommandDocument(Server $server) { - return $this->createCommandDocument(); + $cmd = $this->createCommandDocument(); + + // Read concern can change the query plan + if (isset($this->options['readConcern'])) { + $cmd['readConcern'] = $this->options['readConcern']; + } + + return $cmd; } /** diff --git a/src/Operation/Find.php b/src/Operation/Find.php index 8f1e56f49..ca91cb94c 100644 --- a/src/Operation/Find.php +++ b/src/Operation/Find.php @@ -331,7 +331,14 @@ public function execute(Server $server) */ public function getCommandDocument(Server $server) { - return $this->createCommandDocument(); + $cmd = $this->createCommandDocument(); + + // Read concern can change the query plan + if (isset($this->options['readConcern'])) { + $cmd['readConcern'] = $this->options['readConcern']; + } + + return $cmd; } /** diff --git a/src/Operation/Update.php b/src/Operation/Update.php index 96a51c53f..611d581d2 100644 --- a/src/Operation/Update.php +++ b/src/Operation/Update.php @@ -228,10 +228,6 @@ public function getCommandDocument(Server $server) $cmd['bypassDocumentValidation'] = $this->options['bypassDocumentValidation']; } - if (isset($this->options['writeConcern'])) { - $cmd['writeConcern'] = $this->options['writeConcern']; - } - return $cmd; }