I have a database with many nodes and many entity references. The node access table is rather big. Before I updated to version 1.1 everything was nice performant. But with the update to version 1.1 the performance is very bad. So I installed XHProf and check what is the problem and it seams to be related to the query generation. Please see

Version 1.1
http://screencast.com/t/5lMjsJbPd

Version 1.0
http://screencast.com/t/xBDp1pMvq6xN

Is there a significant change in code that may lead to these performance impacts?

Comments

manuelBS’s picture

I now figured out that due to the commit
http://drupalcode.org/project/entityreference.git/commitdiff/92747d93914...

The issue occured as for every entityreference in a view node_access is executed. In an installation with big grant tables, this will lead to the benchmarks as listed above.

bneel’s picture

Priority: Normal » Major
Issue tags: +Performance, +node_access

I confirm the performance issue.

If there is 300 nodes in the entityreference select form, there will be 300 node_access calls and 300 more queries...

The commit #1 needs to be reverted.

I changed the issue as Major, because the module is not usable if you have 10 or more entityReferencable nodes.

sunshinee’s picture

Just posting to confirm the problem. The node load time prior to this update was less than 0.5 seconds and jumped to more than 3 minutes after the update... all other factors equal. We will be reverting this change in our test environment and post back with updates.

sunshinee’s picture

I forgot to come back to this, but reverting the commit does resolve the issue. We are using entity reference heavily with hundreds of nodes that can be referenced in a field collection (literally thousands of node_access checks).

Could the node_access check be executed only on change? For example, if I have rights to edit the content, load the Edit page as expected, then execute node-access only if I modify or add an entityreference?

Exploratus’s picture

Whatever happened with this?

mustanggb’s picture

Status: Active » Closed (cannot reproduce)
ShadowMonster’s picture

Version: 7.x-1.1 » 7.x-1.5
Status: Closed (cannot reproduce) » Needs work

This is still an issue.

Entity reference is doing node_access check in:

$has_view_access = (entity_access('view', $target_type, $target_entities[$item[$column]]) !== FALSE);
$has_update_access = (entity_access('update', $target_type, $target_entities[$item[$column]]) !== FALSE);
$items[$id][$delta]['access'] = ($has_view_access || $has_update_access);

in entityreference_field_formatter_prepare_view

In some point it have sense but when You prepare view and You don't use any referenced items it simply check all referenced nodes what doesn't make any sense if any of them is not in use. It simply is not aware of that situation. We have ex. one node to be referenced by hundreds other and performance will go down to few minutes from few seconds.

We have to use custom hack to turn off this check for views.

Witch some very advanced caching (we use that ones - we cache node_access for some minutes) You may not fell it until this cache will have to be cleaned. So our users has been use view it work fine until they do not make some changes and cache have to be cleaned what make them very frustrated as it was taking a lot time to recheck all accesses.

This need more work. Maybe simple option or hook to control it will fix it.