Skip to content

Commit

Permalink
Reduced Ibexa\Core\Persistence\Legacy\Content\Type\Mapper::extractTyp…
Browse files Browse the repository at this point in the history
…esFromRows computational complexity from n^2 to 2n
  • Loading branch information
adamwojs committed Oct 21, 2024
1 parent c338dc5 commit 5d53e91
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/lib/Persistence/Legacy/Content/Type/Mapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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])) {
Expand All @@ -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);

Expand Down

0 comments on commit 5d53e91

Please sign in to comment.