From 5da904edef67b54b4c65ed2b30cc435504ee03f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20W=C3=B3js?= Date: Mon, 21 Oct 2024 20:35:21 +0200 Subject: [PATCH] Reduced Ibexa\Core\Persistence\Legacy\Content\Type\Mapper::extractTypesFromRows computational complexity from n^2 to 2n --- .../Persistence/Legacy/Content/Type/Mapper.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/lib/Persistence/Legacy/Content/Type/Mapper.php b/src/lib/Persistence/Legacy/Content/Type/Mapper.php index af8c060d95..71dc8a2f81 100644 --- a/src/lib/Persistence/Legacy/Content/Type/Mapper.php +++ b/src/lib/Persistence/Legacy/Content/Type/Mapper.php @@ -57,9 +57,9 @@ public function __construct( * * @param \Ibexa\Contracts\Core\Persistence\Content\Type\Group\CreateStruct $struct * - * @todo $description is not supported by database, yet - * * @return \Ibexa\Contracts\Core\Persistence\Content\Type\Group + * + * @todo $description is not supported by database, yet */ public function createGroupFromCreateStruct(GroupCreateStruct $struct) { @@ -119,6 +119,16 @@ public function extractTypesFromRows(array $rows, bool $keepTypeIdAsKey = false) $types = []; $fields = []; + $rowsByAttributeId = []; + foreach ($rows as $row) { + $attributeId = (int)$row['ezcontentclass_attribute_id']; + if (!isset($rowsByAttributeId[$attributeId])) { + $rowsByAttributeId[$attributeId] = []; + } + + $rowsByAttributeId[$attributeId][] = $row; + } + foreach ($rows as $row) { $typeId = (int)$row['ezcontentclass_id']; if (!isset($types[$typeId])) { @@ -128,9 +138,7 @@ public function extractTypesFromRows(array $rows, bool $keepTypeIdAsKey = false) $fieldId = (int)$row['ezcontentclass_attribute_id']; if ($fieldId && !isset($fields[$fieldId])) { - $fieldDataRows = array_filter($rows, static function (array $row) use ($fieldId) { - return (int) $row['ezcontentclass_attribute_id'] === (int) $fieldId; - }); + $fieldDataRows = $rowsByAttributeId[$fieldId]; $multilingualData = $this->extractMultilingualData($fieldDataRows);