Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBX-9289: NodeFactory optimization #1405

Merged
merged 3 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/bundle/Controller/Content/ContentTreeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public function loadNodeExtendedInfoAction(Location $location): NodeExtendedInfo
fn (string $languageCode): bool => $this->isPreviewable($location, $content, $languageCode)
);

return new NodeExtendedInfo($locationPermissionRestrictions, $previewableTranslations);
return new NodeExtendedInfo($locationPermissionRestrictions, $previewableTranslations, $translations);
}

/**
Expand Down
2 changes: 0 additions & 2 deletions src/lib/REST/Output/ValueObjectVisitor/ContentTree/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ public function visit(Visitor $visitor, Generator $generator, $data)

$generator->valueElement('versionNo', $data->versionNo);

$generator->valueElement('translations', implode(',', $data->translations));

$generator->valueElement('mainLanguageCode', $data->mainLanguageCode);

$generator->startValueElement('name', $data->name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function visit(Visitor $visitor, Generator $generator, $data): void

$this->buildPermissionNode($data->getPermissionRestrictions(), $generator);
$this->buildPreviewableTranslationsNode($data->getPreviewableTranslations(), $generator);
$this->buildTranslationsNode($data->getTranslations(), $generator);

$generator->endObjectElement(self::MAIN_ELEMENT);
}
Expand All @@ -51,6 +52,22 @@ protected function buildPreviewableTranslationsNode(
$generator->endHashElement('previewableTranslations');
}

/**
* @param array<int, string> $translations
*/
protected function buildTranslationsNode(
array $translations,
Generator $generator
): void {
$generator->startHashElement('translations');
$generator->startList('values');
foreach ($translations as $value) {
$generator->valueElement('value', $value);
}
$generator->endList('values');
$generator->endHashElement('translations');
}

/**
* @phpstan-param TPermissionRestrictions $permissionRestrictions
*/
Expand Down
17 changes: 1 addition & 16 deletions src/lib/REST/Value/ContentTree/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ class Node extends RestValue

public int $versionNo;

/** @var string[] */
public array $translations;

/** @var string */
public $name;

Expand Down Expand Up @@ -56,24 +53,13 @@ class Node extends RestValue
public string $mainLanguageCode;

/**
* @param int $depth
* @param int $locationId
* @param int $contentId
* @param string[] $translations
* @param string $name
* @param string $contentTypeIdentifier
* @param bool $isContainer
* @param bool $isInvisible
* @param int $displayLimit
* @param int $totalChildrenCount
* @param \Ibexa\AdminUi\REST\Value\ContentTree\Node[] $children
* @param array<\Ibexa\AdminUi\REST\Value\ContentTree\Node> $children
*/
public function __construct(
int $depth,
int $locationId,
int $contentId,
int $versionNo,
array $translations,
string $name,
string $contentTypeIdentifier,
bool $isContainer,
Expand All @@ -90,7 +76,6 @@ public function __construct(
$this->locationId = $locationId;
$this->contentId = $contentId;
$this->versionNo = $versionNo;
$this->translations = $translations;
$this->name = $name;
$this->isInvisible = $isInvisible;
$this->contentTypeIdentifier = $contentTypeIdentifier;
Expand Down
22 changes: 18 additions & 4 deletions src/lib/REST/Value/ContentTree/NodeExtendedInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,26 @@ final class NodeExtendedInfo extends RestValue
/** @phpstan-var TPermissionRestrictions|null */
private ?array $permissions;

/** @var string[] */
/** @var array<int, string> */
private array $previewableTranslations;

/** @var array<int, string> */
private array $translations;

/**
* @phpstan-param TPermissionRestrictions|null $permissions
*
* @param string[] $previewableTranslation
* @param array<int, string> $previewableTranslation
* @param array<int, string> $translations
*/
public function __construct(
?array $permissions = null,
array $previewableTranslation = []
array $previewableTranslation = [],
array $translations = []
) {
$this->permissions = $permissions;
$this->previewableTranslations = $previewableTranslation;
$this->translations = $translations;
}

/**
Expand All @@ -53,10 +59,18 @@ public function getPermissionRestrictions(): ?array
}

/**
* @return string[]
* @return array<int, string>
*/
public function getPreviewableTranslations(): array
{
return $this->previewableTranslations;
}

/**
* @return array<int, string>
*/
public function getTranslations(): array
{
return $this->translations;
}
}
11 changes: 2 additions & 9 deletions src/lib/UI/Module/ContentTree/NodeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,6 @@ private function buildNode(
$containerLocations[] = $location;
}

$content = $location->getContent();
$versionInfo = $content->getVersionInfo();

$limit = $this->resolveLoadLimit($loadSubtreeRequestNode);
$offset = null !== $loadSubtreeRequestNode
? $loadSubtreeRequestNode->offset
Expand Down Expand Up @@ -391,15 +388,11 @@ private function buildNode(
}
}

$translations = $versionInfo->getLanguageCodes();
$mainLanguageCode = $versionInfo->getContentInfo()->getMainLanguageCode();

return new Node(
$depth,
$location->getId(),
$location->getContentId(),
$versionInfo->getVersionNo(),
$translations,
$contentInfo->currentVersionNo,
'', // node name will be provided later by `supplyTranslatedContentName` method
null !== $contentType ? $contentType->getIdentifier() : '',
null === $contentType || $contentType->isContainer(),
Expand All @@ -408,7 +401,7 @@ private function buildNode(
$totalChildrenCount,
$this->getReverseRelationsCount($contentInfo),
isset($bookmarkLocations[$location->getId()]),
$mainLanguageCode,
$contentInfo->getMainLanguageCode(),
$children,
$location->getPathString()
);
Expand Down
2 changes: 0 additions & 2 deletions tests/integration/Resources/REST/Schemas/ContentTreeNode.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@
"pathString",
"contentId",
"versionNo",
"translations",
"name",
"contentTypeIdentifier",
"isContainer",
Expand All @@ -109,7 +108,6 @@
"pathString",
"contentId",
"versionNo",
"translations",
"name",
"contentTypeIdentifier",
"isContainer",
Expand Down
2 changes: 0 additions & 2 deletions tests/integration/Resources/REST/Schemas/ContentTreeNode.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<xs:element type="xs:string" name="pathString"/>
<xs:element type="xs:integer" name="contentId"/>
<xs:element type="xs:integer" name="versionNo"/>
<xs:element type="xs:string" name="translations"/>
<xs:element type="xs:string" name="mainLanguageCode"/>
<xs:element type="xs:string" name="name"/>
<xs:element type="xs:string" name="contentTypeIdentifier"/>
Expand All @@ -24,7 +23,6 @@
<xs:element type="xs:string" name="pathString"/>
<xs:element type="xs:integer" name="contentId"/>
<xs:element type="xs:integer" name="versionNo"/>
<xs:element type="xs:string" name="translations"/>
<xs:element type="xs:string" name="mainLanguageCode"/>
<xs:element type="xs:string" name="name"/>
<xs:element type="xs:string" name="contentTypeIdentifier"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,26 @@
]
}
}
}
},
"translations": {
"type": "object",
"properties": {
"values": {
"type": "array",
"items": [
{
"type": "string"
}
]
}
}
}
},
"required": [
"_media-type",
"permissions",
"previewableTranslations"
"previewableTranslations",
"translations"
]
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="translations">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="value" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="media-type" type="xs:string" use="required" />
</xs:complexType>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"pathString": "/1/2/",
"reverseRelationsCount": 0,
"totalChildrenCount": 0,
"translations": "eng-GB",
"versionNo": 1
},
{
Expand All @@ -35,7 +34,6 @@
"pathString": "/1/43/",
"reverseRelationsCount": 0,
"totalChildrenCount": 3,
"translations": "eng-US",
"versionNo": 1
},
{
Expand All @@ -53,7 +51,6 @@
"pathString": "/1/48/",
"reverseRelationsCount": 0,
"totalChildrenCount": 0,
"translations": "eng-US",
"versionNo": 1
},
{
Expand All @@ -71,7 +68,6 @@
"pathString": "/1/58/",
"reverseRelationsCount": 0,
"totalChildrenCount": 0,
"translations": "eng-US",
"versionNo": 1
}
],
Expand All @@ -87,7 +83,6 @@
"pathString": "/1/",
"reverseRelationsCount": 0,
"totalChildrenCount": 4,
"translations": "",
"versionNo": 1
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"pathString": "/1/43/",
"reverseRelationsCount": 0,
"totalChildrenCount": 0,
"translations": "eng-US",
"versionNo": 1
}
],
Expand All @@ -33,7 +32,6 @@
"pathString": "/1/",
"reverseRelationsCount": 0,
"totalChildrenCount": 1,
"translations": "",
"versionNo": 1
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"pathString": "/1/43/",
"reverseRelationsCount": 0,
"totalChildrenCount": 3,
"translations": "eng-US",
"versionNo": 1
},
{
Expand All @@ -35,7 +34,6 @@
"pathString": "/1/48/",
"reverseRelationsCount": 0,
"totalChildrenCount": 0,
"translations": "eng-US",
"versionNo": 1
},
{
Expand All @@ -53,7 +51,6 @@
"pathString": "/1/5/",
"reverseRelationsCount": 0,
"totalChildrenCount": 5,
"translations": "eng-US",
"versionNo": 1
},
{
Expand All @@ -71,7 +68,6 @@
"pathString": "/1/58/",
"reverseRelationsCount": 0,
"totalChildrenCount": 0,
"translations": "eng-US",
"versionNo": 1
}
],
Expand All @@ -87,7 +83,6 @@
"pathString": "/1/",
"reverseRelationsCount": 0,
"totalChildrenCount": 4,
"translations": "",
"versionNo": 1
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"pathString": "/1/43/",
"reverseRelationsCount": 0,
"totalChildrenCount": 3,
"translations": "eng-US",
"versionNo": 1
},
{
Expand All @@ -35,7 +34,6 @@
"pathString": "/1/48/",
"reverseRelationsCount": 0,
"totalChildrenCount": 0,
"translations": "eng-US",
"versionNo": 1
},
{
Expand All @@ -53,7 +51,6 @@
"pathString": "/1/58/",
"reverseRelationsCount": 0,
"totalChildrenCount": 0,
"translations": "eng-US",
"versionNo": 1
}
],
Expand All @@ -69,7 +66,6 @@
"pathString": "/1/",
"reverseRelationsCount": 0,
"totalChildrenCount": 3,
"translations": "",
"versionNo": 1
}
}
Loading
Loading