Problem/Motivation

I would like to add some more relationships and a summary field to make it easier to create administrative views. The relationships open up a lot more options for adding fields and filtering if using views for anything. The relationships are:

  • Direct parent (classic entity reference)
  • Direct children (classic reverse entity reference)
  • Hierarchy root (custom join created from nested set data)

This also includes the code and test from https://www.drupal.org/project/entity_hierarchy/issues/3199594 which is just displaying a summary like "3 / 2 / 6" for a quick idea of how many children are below the current entity.

sample image 1
sample image 2

Comments

sime created an issue. See original summary.

sime’s picture

sime’s picture

Issue summary: View changes
sime’s picture

Issue summary: View changes
sime’s picture

Status: Active » Needs review

Tests and linting included.

Status: Needs review » Needs work

The last submitted patch, 2: entity_hierarchy-3199836-relationships.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

sime’s picture

sime’s picture

Linting

sime’s picture

Status: Needs work » Needs review
sime’s picture

Just looking at isolated query performance of the Root relationship i get 250ms in prod for 50 records. This being the query for the /admin/content view, plus the root relationship.

SELECT node_field_data.nid AS nid, users_field_data_node_field_data.uid AS users_field_data_node_field_data_uid, eh_for_node_field_data.nid AS eh_for_node_field_data_nid
FROM
node_field_data node_field_data
INNER JOIN users_field_data users_field_data_node_field_data ON node_field_data.uid = users_field_data_node_field_data.uid
LEFT JOIN (SELECT eh_child.id AS eh_child_id, eh_child.revision_id AS eh_child_revision_id, eh_parent.id AS nid
FROM
nested_set_field_parent_node eh_child
INNER JOIN nested_set_field_parent_node eh_parent ON (eh_child.left_pos BETWEEN eh_parent.left_pos AND eh_parent.right_pos) AND eh_parent.depth = 0) eh_for_node_field_data ON node_field_data.nid = eh_for_node_field_data.eh_child_id
WHERE (node_field_data.status = 1 OR (node_field_data.uid = 1 AND 1 <> 0 AND 1 = 1) OR 1 = 1 OR 1 = 1)
ORDER BY node_field_data.changed DESC
LIMIT 50 OFFSET 0

If i up this too much, or add a sort on say eh_for_node_field_data.nid, which I think will need to query the whole result first to then apply the sort and limit, then it starts to slow down. I'm not sure what this should scale too.

sime’s picture

Status: Needs review » Needs work

There's a cross join in the root relationship.

sime’s picture

Correction, it's missing the vid/revision in the WHERE. That explains the slowness...

sime’s picture

StatusFileSize
new64.16 KB

Fixes the join to include revision key if appropriate.

+ if ($revision_key = $entity_type->getKey('revision_id')) {

+ if ($revision_key = $entity_type->getKey('revision')) {

sime’s picture

1000 rows on this site is more performant now.

SELECT node_field_data.nid AS nid, users_field_data_node_field_data.uid AS users_field_data_node_field_data_uid, eh_for_node_field_data.nid AS eh_for_node_field_data_nid
FROM
node_field_data node_field_data
INNER JOIN users_field_data users_field_data_node_field_data ON node_field_data.uid = users_field_data_node_field_data.uid
LEFT JOIN (SELECT eh_child.id AS eh_child_id, eh_child.revision_id AS eh_child_revision_id, eh_parent.id AS nid
FROM
nested_set_field_parent_node eh_child
INNER JOIN nested_set_field_parent_node eh_parent ON (eh_child.left_pos BETWEEN eh_parent.left_pos AND eh_parent.right_pos) AND eh_parent.depth = 0) eh_for_node_field_data ON node_field_data.nid = eh_for_node_field_data.eh_child_id AND eh_for_node_field_data.eh_child_revision_id = node_field_data.vid
WHERE (node_field_data.status = 1 OR (node_field_data.uid = 1 AND 1 <> 0 AND 1 = 1) OR 1 = 1 OR 1 = 1)
ORDER BY node_field_data.changed DESC
LIMIT 1000 OFFSET 2000
sime’s picture

  1. Needs a test for entitys with revisions
  2. If you do a relationship to root, you can do a filter on root node ID, and you can display title/fields, but you can't do a filter on the title of the root node.
sime’s picture

Title: New entity references and summary field » New relationships and summary field
larowlan’s picture

These are looking great, thanks sime

larowlan’s picture

Status: Needs work » Needs review
StatusFileSize
new34.22 KB
new127.39 KB

Here's some tests for revisionable entity-types.

I think this should be a follow-up issue:

If you do a relationship to root, you can do a filter on root node ID, and you can display title/fields, but you can't do a filter on the title of the root node.

larowlan credited Vj.

larowlan’s picture

larowlan’s picture

Status: Needs review » Needs work

The last submitted patch, 21: 3199836-21.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

larowlan’s picture

Status: Needs work » Needs review
StatusFileSize
new129.67 KB
larowlan’s picture

Status: Needs review » Fixed

This will be 3.0.0-rc1

Let's get some eyes on it

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

delacosta456’s picture

hi
It'z looks like the is a bug related to relation ship.

When settings up the relationship without enabling "require this relationship", when on view preview and logged in as admin everything display as expected for administrator

But when logging with another user with different role that has necessary permission the view behave like if "require this relationship" was enabled