Skip to content

Performance: /api/content_node/checklist_nodes #7114

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

Merged
merged 2 commits into from
Apr 11, 2025
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
27 changes: 27 additions & 0 deletions api/migrations/schema/Version20250324224924.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20250324224924 extends AbstractMigration {
public function getDescription(): string {
return 'ContentNode.RootId not nullable';
}

public function up(Schema $schema): void {
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE content_node ALTER rootId SET NOT NULL');
}

public function down(Schema $schema): void {
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE content_node ALTER rootid DROP NOT NULL');
}
}
7 changes: 6 additions & 1 deletion api/src/Entity/ContentNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ abstract class ContentNode extends BaseEntity implements BelongsToContentNodeTre
#[Gedmo\SortableGroup] // this is needed to avoid that all root nodes are in the same sort group (parent:null, slot: '')
#[Groups(['read'])]
#[ORM\ManyToOne(targetEntity: ColumnLayout::class, inversedBy: 'rootDescendants')]
#[ORM\JoinColumn(nullable: true, onDelete: 'CASCADE')] // TODO make not null in the DB using a migration, and get fixtures to run
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, so this finally works now

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes - and it improves performance :)

public ?ColumnLayout $root = null;

/**
Expand Down Expand Up @@ -186,6 +186,11 @@ public function getParent(): ?HasParentInterface {
return $this->parent;
}

public function setParent(?ContentNode $parent) {
$this->parent = $parent;
$this->root ??= $parent?->root;
}

/**
* Holds the actual data of the content node.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function testCreateColumnLayoutValidatesMissingParent() {
$this->assertJsonContains([
'violations' => [
[
'propertyPath' => 'parent',
'propertyPath' => 'root',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test name still says the parent may not be missing, not the root. Should this be a new test instead? Or do we just need to adjust the test's name?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately no.
parent is the mandatory field. But without parent root is not determined.
Unfortunately root is checked first.
It is correct that a ValidationError occurs. However, the message is unfortunate.
Unfortunately, I have not found a better solution.

'message' => 'This value should not be null.',
],
],
Expand Down
Loading
Loading