Skip to content

Commit f555028

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

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* @copyright Copyright (C) Ibexa AS. All rights reserved.
55
* @license For full copyright and license information view LICENSE file distributed with this source code.
66
*/
7+
78
namespace Ibexa\Core\Persistence\Legacy\Content\Type;
89

910
use Ibexa\Contracts\Core\Persistence\Content\Type;
@@ -57,9 +58,9 @@ public function __construct(
5758
*
5859
* @param \Ibexa\Contracts\Core\Persistence\Content\Type\Group\CreateStruct $struct
5960
*
61+
* @return \Ibexa\Contracts\Core\Persistence\Content\Type\Group
6062
* @todo $description is not supported by database, yet
6163
*
62-
* @return \Ibexa\Contracts\Core\Persistence\Content\Type\Group
6364
*/
6465
public function createGroupFromCreateStruct(GroupCreateStruct $struct)
6566
{
@@ -119,6 +120,16 @@ public function extractTypesFromRows(array $rows, bool $keepTypeIdAsKey = false)
119120
$types = [];
120121
$fields = [];
121122

123+
$rowsByAttributeId = [];
124+
foreach ($rows as $row) {
125+
$attributeId = (int)$row['ezcontentclass_attribute_id'];
126+
if (!isset($rowsByAttributeId[$attributeId])) {
127+
$rowsByAttributeId[$attributeId] = [];
128+
}
129+
130+
$rowsByAttributeId[$attributeId][] = $row;
131+
}
132+
122133
foreach ($rows as $row) {
123134
$typeId = (int)$row['ezcontentclass_id'];
124135
if (!isset($types[$typeId])) {
@@ -128,9 +139,7 @@ public function extractTypesFromRows(array $rows, bool $keepTypeIdAsKey = false)
128139
$fieldId = (int)$row['ezcontentclass_attribute_id'];
129140

130141
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-
});
142+
$fieldDataRows = $rowsByAttributeId[$fieldId];
134143

135144
$multilingualData = $this->extractMultilingualData($fieldDataRows);
136145

0 commit comments

Comments
 (0)