Shouldn't deletion of a node also remove the rows in node_access with the matching nid? Leaving them behind just makes the node_access table larger than it needs to be, eventually adversely affecting performance.

CommentFileSizeAuthor
#27 118108.patch857 bytesbleen
#25 118108.patch533 bytesbleen
#17 node_access.patch780 bytesbleen
#15 node_access.patch1.52 KBbleen
#8 nodeaccess.patch748 bytesbleen
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

moshe weitzman’s picture

Project: Organic groups » Drupal core
Version: 5.x-1.x-dev » 6.x-dev
Component: og.module » node system

node.module manages the node_access table by arbitrating all writes. moving to core

cburschka’s picture

So should the patched node_delete do DELETE FROM {node_access} WHERE nid=%d itself, or should it call node_access_write_grants($node, array());?

Ready to patch...

cburschka’s picture

Also, how about adding a node_update_N() that retroactively cleans {node_access}?

moshe weitzman’s picture

it should delete by itself. an update function makes sense if one query can just delete all the orphans. if you have ot iterate over all nodes, then a node_access_rebuild() is in order.

cburschka’s picture

Doing this in one query would require an outer join followed by deleting all the entries that are joined with null. However, I don't believe it's possible to join and delete in the same query (my SQL-fu is weak). When I need to do something similar, I first run a joined update that marks the entries as "deletable", then delete the marked fields in a second query, which still avoids iterating.

Compatibility with PostGre is another matter, but I've been able to get MySQL 4 and 5 to do this:

UPDATE {node_access} a LEFT JOIN {node} n ON a.nid=n.nid SET realm = 'temp_delete' WHERE n.nid IS NULL;
DELETE FROM {node_access} WHERE realm = 'temp_delete';

This could be called a hack, though, so I'm not sure.

wedge’s picture

DELETE FROM {node_access} WHERE nid NOT IN (SELECT nid FROM {node})?

bleen’s picture

Version: 6.x-dev » 7.x-dev
Assigned: Unassigned » bleen

It appears this is still a problem in D7

bleen’s picture

Status: Active » Needs review
FileSize
748 bytes

This should do it ... when this gets committed I'll write a backport.

Status: Needs review » Needs work

The last submitted patch, nodeaccess.patch, failed testing.

bleen’s picture

Status: Needs work » Needs review

#8: nodeaccess.patch queued for re-testing.

bleen’s picture

Issue tags: +Quick fix

bump

moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community

Nice catch.

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Thanks.

bleen’s picture

Version: 7.x-dev » 6.x-dev
Status: Fixed » Patch (to be ported)

This should be ported back to D6 ... Ill slap a patch together this weekend. One question ... should I include an hook_update with the query from #6 with the patch? Thoughts?

bleen’s picture

Status: Patch (to be ported) » Needs review
FileSize
1.52 KB

This is a patch for d6 ...

moshe weitzman’s picture

That update function could take a long time on a huge site. Anyone concerned about that? We could consider fixing the bug but not pruning the table.

bleen’s picture

FileSize
780 bytes

this is a patch without the update function ... I think that an update would be useful, but probably better safe than sorry

Status: Needs review » Needs work
Issue tags: -Quick fix

The last submitted patch, node_access.patch, failed testing.

bleen’s picture

Status: Needs work » Needs review

#17: node_access.patch queued for re-testing.

Status: Needs review » Needs work
Issue tags: +Quick fix

The last submitted patch, node_access.patch, failed testing.

bleen’s picture

hmmm ... any idea why this wont apply?

sixty4rpm’s picture

Sorry to be a pest -- I haven't seen any news on this effort for awhile. No big emergency, it's easy enough to delete the orphan rows by hand in the meantime, but I'm wondering if there is a patch or solution that I have not seen?

Cheers!

bleen’s picture

Status: Needs work » Needs review

#17: node_access.patch queued for re-testing.

Alexander Allen’s picture

Priority: Minor » Major

I'm working in a system where there are half a million nodes, and because of this bug there are around two million entries in the node access table. Looking at two million rows on each page view is adding significantly to database overhead. Let me know if I can help with this.

bleen’s picture

FileSize
533 bytes

lets try this patch

Status: Needs review » Needs work

The last submitted patch, 118108.patch, failed testing.

bleen’s picture

Status: Needs work » Needs review
FileSize
857 bytes

maybe this one....

Status: Needs review » Needs work

The last submitted patch, 118108.patch, failed testing.

naxoc’s picture

Status: Needs work » Reviewed & tested by the community

The bot complains that the patch does not apply. It does apply and look fine to me, so I am RTBC-ing it.

lcollet’s picture

Dear all,

Personnally, I used hook_node_grants, hook_node_access_records and to avoid having dead rows in my databse, I just implemented the hook_nodeapi to solve this problem. See below.

It prevented me touching the core and it is implemented quite easily! :p

function custom_access_nodeapi( &$node, $op, $a3 = NULL, $a4 = NULL ){
    if ( $op == 'delete' ) {
        db_query( "DELETE FROM {node_access} WHERE nid = {$node->nid};" );
    }
}
Gábor Hojtsy’s picture

Status: Reviewed & tested by the community » Fixed

I agree it is fine to not do an update function here. Better be safe. Committed the last patch. Thanks!

Status: Fixed » Closed (fixed)
Issue tags: -Quick fix

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