Skip to content

Conversation

@solracsf
Copy link
Member

No description provided.

Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>
@solracsf solracsf added the 3. to review Items that need to be reviewed label Dec 31, 2025
Comment on lines -271 to +259
$paths = array_merge($paths, $query->executeQuery()->fetchAll(\PDO::FETCH_COLUMN));
array_push($paths, ...$query->executeQuery()->fetchAll(\PDO::FETCH_COLUMN));
Copy link
Contributor

Choose a reason for hiding this comment

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

I’m afraid this may be less efficient, it will expand the whole array into function parameters instead of passing 2 arrays to array_merge. Do you have a reference on why this would be better?

Copy link
Member Author

Choose a reason for hiding this comment

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

Each call to array_merge() creates a new array by copying all existing elements plus the new ones. array_push() with the spread operator ... appends elements directly to the existing array without creating copies.

However, you might be right that spreading into function parameters isn't ideal.
The optimal approach may be to collect arrays first, then merge once:

$chunks = [];
foreach (array_chunk($pathHashes, 1000) as $chunk) {
	$query->setParameter('chunk', $chunk, IQueryBuilder::PARAM_STR_ARRAY);
	$chunks[] = $query->executeQuery()->fetchAll(\PDO::FETCH_COLUMN);
}
$paths = array_merge(...$chunks);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to review Items that need to be reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants