Skip to content
This repository was archived by the owner on Feb 28, 2025. It is now read-only.

Allow to merge an array of stages into a pipeline #57

Merged
merged 3 commits into from
Mar 15, 2024

Conversation

GromNaN
Copy link
Member

@GromNaN GromNaN commented Jan 26, 2024

Coming from https://github.com/mongodb/mongo-php-builder/pull/56/files#r1466461225

I feel that a list of stages is a valid type for a pipeline. We already allowed merging Pipeline objects, we can make things more efficient by avoiding the intermediate Pipeline object when we already have an array.

alcaeus
alcaeus previously approved these changes Jan 29, 2024
@@ -36,7 +39,9 @@ public function __construct(StageInterface|Pipeline ...$stagesOrPipelines)
$stages = [];

foreach ($stagesOrPipelines as $stageOrPipeline) {
if ($stageOrPipeline instanceof Pipeline) {
if (is_array($stageOrPipeline) && array_is_list($stageOrPipeline)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed you don't check whether each item in the list is a StageInterface instance. In theory, this should be fine as PipelineEncoder uses encodeIfSupported to encode each stage. Anything the encoder can't handle will be sent to the server as is, potentially causing an execution error later. This would allow users to inject raw pipeline stages (e.g. if they want to use something not supported by their builder version) as long as they know what they are doing.

@GromNaN GromNaN changed the base branch from 0.1 to 0.2 March 13, 2024 16:51
@GromNaN GromNaN force-pushed the merge-pipeline-array branch from a43469a to 80a35cd Compare March 14, 2024 10:45
@GromNaN GromNaN force-pushed the merge-pipeline-array branch from 9b96cc9 to 0850040 Compare March 15, 2024 10:27
@GromNaN GromNaN merged commit 7c3375d into mongodb:0.2 Mar 15, 2024
@GromNaN GromNaN deleted the merge-pipeline-array branch March 15, 2024 12:38
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants