Skip to content

Commit 5d53e91

Browse files
committed
Reduced Ibexa\Core\Persistence\Legacy\Content\Type\Mapper::extractTypesFromRows computational complexity from n^2 to 2n
1 parent c338dc5 commit 5d53e91

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/lib/Persistence/Legacy/Content/Type/Mapper.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ public function __construct(
5757
*
5858
* @param \Ibexa\Contracts\Core\Persistence\Content\Type\Group\CreateStruct $struct
5959
*
60-
* @todo $description is not supported by database, yet
61-
*
6260
* @return \Ibexa\Contracts\Core\Persistence\Content\Type\Group
61+
*
62+
* @todo $description is not supported by database, yet
6363
*/
6464
public function createGroupFromCreateStruct(GroupCreateStruct $struct)
6565
{
@@ -119,6 +119,16 @@ public function extractTypesFromRows(array $rows, bool $keepTypeIdAsKey = false)
119119
$types = [];
120120
$fields = [];
121121

122+
$rowsByAttributeId = [];
123+
foreach ($rows as $row) {
124+
$attributeId = (int)$row['ezcontentclass_attribute_id'];
125+
if (!isset($rowsByAttributeId[$attributeId])) {
126+
$rowsByAttributeId[$attributeId] = [];
127+
}
128+
129+
$rowsByAttributeId[$attributeId][] = $row;
130+
}
131+
122132
foreach ($rows as $row) {
123133
$typeId = (int)$row['ezcontentclass_id'];
124134
if (!isset($types[$typeId])) {
@@ -128,9 +138,7 @@ public function extractTypesFromRows(array $rows, bool $keepTypeIdAsKey = false)
128138
$fieldId = (int)$row['ezcontentclass_attribute_id'];
129139

130140
if ($fieldId && !isset($fields[$fieldId])) {
131-
$fieldDataRows = array_filter($rows, static function (array $row) use ($fieldId) {
132-
return (int) $row['ezcontentclass_attribute_id'] === (int) $fieldId;
133-
});
141+
$fieldDataRows = $rowsByAttributeId[$fieldId];
134142

135143
$multilingualData = $this->extractMultilingualData($fieldDataRows);
136144

0 commit comments

Comments
 (0)