Closed (fixed)
Project:
Node access node reference
Version:
7.x-1.x-dev
Component:
Code
Priority:
Critical
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
11 Jul 2012 at 06:06 UTC
Updated:
20 Aug 2012 at 05:21 UTC
Jump to comment: Most recent file
Comments
Comment #1
danielb commentedI fail to see how this is a bug.
So 0.14ms per page load?
Seems pretty reasonable.
If you've got a lot of node references, and a lot of visitors (300 hits per minute??), but limited resources on the server, then this might not be the module for you.
Comment #2
stefan81 commentedThank you for your feedback.
Actually, I copied the site to my local machine to debug it. So I was the only user.
I am not sure if my node references are producing some kind of a loop. Will investigate it.
Idea:
Now we can do the following settings on node references:
- always
- only if in use
Would it help to explicitly set to
- never?
I have many (4) node references on nodes.
But only one field passes on acess settings.
Are fields without any settings activated ignored?
Comment #3
johnvI second this request (on D7).
In my case the function is called 500 times in 1 page request, because I have 600 possible referenced nodes.
IMO the culprit is:
which is called every time, when a non-relevant node is viewed. That needs two repairs:#3-1: no cacheflushing (via 'This line') when viewing content, only on change/delete
#3-2: no cacheflushing (via 'This line') (and no expensive calls) when a entitytype has no settings for NANR.
EDIT: this is only when you have one of the blocks devel_node_access/dna_node or devel_node_access/dna_node enabled. So, this module does not cause that problem.
stefan81's idea seems like a good solution.
- If always/only_in_use is selected, you can do get_referenced()
- If 'never' is used, $field_data would be empty, so not relevant, AND the variable_set should not be called.
Somehow, the variable_set should only be done when saving/deleting a node, that is on node_page_edit();
There is some problem with the recursive calling, and the cache_clear should only be done once per page-request.
I was trying to create a patch on the [unused] field, but I am unsure when the variable_set() is still valid.
For now, I move above line inside the brackets.
Comment #4
johnvI did a dpm(debug_backtrace()); on one of the hook_node_access() calls. Below the most important lines.
0 =
function (String, 15 characters ) abt_node_access | (Callback) abt_node_access(); args (Array, 3 elements)
3 =
file \nodeaccess_nodereference\nodeaccess_nodereference.moduleline
function (String, 11 characters ) node_access | (Callback) node_access();
4 =
file \nodeaccess_nodereference\nodeaccess_nodereference.moduleline (Integer) 44
function nodeaccess_nodereference_calculate_grants | (Callback) nodeaccess_nodereference_calculate_grants();
5 =
function nodeaccess_nodereference_node_grants | (Callback) nodeaccess_nodereference_node_grants();
8 =
file \modules\node\node.moduleline (Integer) 2914
function node_access_grants | (Callback) node_access_grants();
9 =
function node_access | (Callback) node_access();
11 =
file \includes\menu.inc line (Integer) 775
function (String, 18 characters ) _menu_check_access | (Callback) _menu_check_access();
13 =
file \includes\menu.inc ;
function menu_get_item | (Callback) menu_get_item();
17 =
file \index.php ;
function drupal_bootstrap | (Callback) drupal_bootstrap();
Comment #5
johnvBtw, this is also for authenticated users
Comment #6
danielb commentedI'm not following this at all. I get that nodeaccess_nodereference_get_referenced() is being called a lot - but.. you have a lot of nodes and node references... I don't see a way around that at this stage. It is the unfortunate design of the Drupal node access system that at the time of viewing/updating/deleting the node and deciding whether to allow the user to do it: we don't know what the node is, so we have to build a picture of the whole site and that means all relevant references are looked at. Obviously once you have a reasonable quantity of nodes, this solution is ridiculous.
The queries in nodeaccess_nodereference_get_referenced() will not be called if the field does not have settings enabled from this module, so the 'never' setting seems irrelevant. At least this is the intention of the code that is in dev.
The cache is only cleared after a relevant node has it's access rebuilt, as updated field information can break chains of node access. It does not clear on every page load as you say. The statement you've moved should probably remain where it is, as it should mark the cache as bad when the node has NANR fields, but also importantly: when it does not have NANR fields - as it could previously have had them.
Comment #7
danielb commentedOK how about this,
rewrite nodeaccess_nodereference_get_referenced() to also select entity_id
make only a single call to it once, without supplying a $nid, and store all the returned data in a static cache (maybe even a persistent cache), keyed by entity_id.
Then subsequent calls to nodeaccess_nodereference_get_referenced($nid) would simply lookup the cache.
Comment #8
danielb commentedalong the lines of what I was talking about.
Comment #9
danielb commentedthis approach will cache the map of references across different page loads and for all users....
Comment #10
stefan81 commentedHello danielb
Thank you for your efforts and time you invested in the patch.
It is very much appreciated!
As it is a drupal 7 specific patch due the drupal_static() function,
I will try to find a workaround to my project.
Comment #11
johnvI have corrected my comment #3 about
variable_set('nodeaccess_nodereference_cache_needs_clear', TRUE)Sorry for being so annoying.
Comment #12
johnvThanks for your patch. I am testing it. These are the results:
1. I sometimes get the error
Fatal error: Cannot use object of type stdClass as array in nodeaccess_nodereference.moduleon the first part of this line:return !empty($references['refs'][$nid]) ? $references['refs'][$nid] : array();in that case, the content is not an array, but:
I am not sure when it happens,: not on a node page, but on a book page.
2. I have 18.000 nodes of 7 node types, of which 40 nodes (each referring to exactly 1 other node) of 1 node type need this module. ATM this query fetches 15000 records, which will be evaluated puposely.
This query should be more specific, and include the node_type:
This requires a substructure $references['refs'][][], I presume?
Comment #13
danielb commentedI've revised it a bit based on these comments.
instead of
$references = &drupal_static(__FUNCTION__);Drupal 6 would usestatic $references = array();or something like that.Comment #14
danielb commentedwe can probably backport these changes easily
Comment #15
johnvPatch #13 work nicely, thanks.
I thought you could read data per node_type (pasing $node instead of $nid), but you need to load all data at once, since hook_node_grants($account, $op) is not per $node.
Comment #16
danielb commentedI've committed that one.
Here is a potential backport.
Comment #17
danielb commentedwell i've committed it
Comment #18
morbiD commentedI don't believe this is working properly.
I just loaded up a fresh D7 install with dev releases of the following modules:
I configured the test site like so:
However, when a user was referenced in A, they only gained update/delete on A; not on B or C.
I tried reverting to the cbeb16d snapshot of nodeaccess_nodereference from git, and the user then gained the correct update/delete permissions on B and C.
Stepping up to the 40c1aba snapshot removed the update/delete permissions on B and C again, so it seems something isn't quite right in the committed patch from this issue.
Comment #19
johnvI have a problem, too
2 identical users should have access to the same node, however, only the Author does (set set in Author-settings). The other one not.
I was still testing my current settings, but perhaps the same sympton as #18.
Comment #20
danielb commentedIf you happen to be testing this the first thing I would do is kill the following line:
To remove caching.
If that doesn't change anything kill the static caching by changing this:
$references = &drupal_static(__FUNCTION__);to this:
$references = array();If it's still a problem then at least we know it wasn't the caching.
Comment #21
morbiD commentedIt's not the caching. I changed both of the above and the problem persisted.
The cause is actually the new return condition:
In
$references = nodeaccess_nodereference_calculate_grants($parent_reference);if$parent_referenceis NULL,nodeaccess_nodereference_get_referenced()returns an empty array because of that new condition.Something like this seems to get it working again:
Comment #22
danielb commentedi might go with something like this?
Comment #23
danielb commentedcommitted, if this is ok I will release
Comment #24
johnvI am on holidays. Cant test these three weeks. Cheers!
Comment #25
morbiD commentedNo problems encountered in my brief testing. Seems good.
Comment #26
danielb commentedThanks guys, I'll mark this issue as fixed then. Any new problems arising from the rewrite of these functions should be reported as a new issue. Cheers!