Improve performance of access checks and add localized sorting

pwolanin - June 25, 2007 - 13:35
Project:Drupal
Version:6.x-dev
Component:menu system
Category:bug report
Priority:normal
Assigned:pwolanin
Status:closed
Description

A follow-on to: http://drupal.org/node/151583 for issues not resolved by that patch.

Function menu_check_access() (and it's helper function) and _menu_tree_data() need to be refactored to make two improvements:

1) use db_rewrite_sql() to check 'view' access to node links, rather than calling node_access() on each one.

2) sort the menu siblings based on the dynamic (localized) link title, rather than using the same sort order for all users.

#1

pwolanin - July 5, 2007 - 21:08
Assigned to:Anonymous» pwolanin
Status:active» needs review

First go at this problem - special case access checks for node links and sort on the localized titles.

AttachmentSizeStatusTest resultOperations
menu_localized_sort_access_1.patch6.22 KBIgnoredNoneNone

#2

pwolanin - July 5, 2007 - 21:31

I can already see one way in which this patch is sub-optimal. It traverses the tree twice on every page view. The first traversal to discover the node links only needs to be done once if there is a way to cache the result together with the tree in a way that it can be re-used later.

Can I store a multi-dimensional array key as a string like $index = "34]['below']['45']['link'"?

It seems unlikely that PHP is smart enough to have references (e.g. $node_links[25] = &tree[45]['link']) persist when I serialize and then unserialize the arrays?

#3

pwolanin - July 6, 2007 - 01:45

to answer my own question:

You can even serialize() arrays that contain references to itself. Circular references inside the array/object you are serialize()ing will also be stored. Any other reference will be lost.

http://us.php.net/manual/en/function.serialize.php

So this *can* work is everything is part of the same array.

#4

pwolanin - July 6, 2007 - 02:50

Ok, here's an implementation using the insight above. The extra tree traversal only happens when building the data for the cache. Tested with PHP 4.4.4.

AttachmentSizeStatusTest resultOperations
menu_localized_sort_access_2.patch9.76 KBIgnoredNoneNone

#5

Gábor Hojtsy - July 6, 2007 - 15:45

Peter asked me to look at this issue. While I don't understand the fine details of the new menu system, sorting by the localized title only works runtime, since the page language is decided on runtime and we can only localize in PHP with the given localization function stored for a menu item.

Custom menu item localization is not built into Drupal 6, so I am not sure we should think about localizing menu items when an item is a node title (and that node has translations). Contributed modules will need to take care of this, so the important part is to allow them to do it.

#6

pwolanin - July 6, 2007 - 16:34

@Gábor - one of the main changes in this patch is to determine the sorting after the titles are localized (as applicable). In this sense, it is a good step forward. I would appreciate you input on what (if any) additional mechanism should be used to enable localizing of link titles. Note that links to nodes may or may not use the node title as the link text, so I'm not sure what the best approach to this would be.

#7

killes@www.drop.org - July 7, 2007 - 19:15

You shouldn't assume that translating by the localized version of a string is best usability by default.

For example, I admin both drupal sites in English and German and the "access" link in the admin navigation menu goes from top to bottom after translation. it is now less annoying than in 4.7 since the sub-menu is shorter, but it still is annoying.

#8

pwolanin - July 7, 2007 - 21:28

minor code and comment cleanup per discussion with Karoly on IRC.

AttachmentSizeStatusTest resultOperations
menu_localized_sort_access_3.patch11.45 KBIgnoredNoneNone

#9

chx - July 7, 2007 - 22:14
Status:needs review» reviewed & tested by the community

killes: People expect alphabetical sorting. If you do not want to have that, assign weights. That's what they are good for.

We presume that the visible menu tree will always be small and also, the node link collection happens before caching. So the performance harm if any, should be very small.

#10

pwolanin - July 15, 2007 - 15:08

patch still applies with minor offset.

#11

Dries - July 16, 2007 - 12:37
Status:reviewed & tested by the community» fixed

Committed to CVS HEAD. Thanks.

#12

pwolanin - July 16, 2007 - 23:44
Status:fixed» reviewed & tested by the community

And of course, as soon as I start working on the book patch, I found a bug in this code that only manifests with deeper node trees.

A foolish mis-ordering of parameters.

AttachmentSizeStatusTest resultOperations
fix_params_1.patch569 bytesIgnoredNoneNone

#13

Gábor Hojtsy - July 17, 2007 - 06:13
Status:reviewed & tested by the community» fixed

Thanks, committed!

#14

Anonymous - July 31, 2007 - 06:15
Status:fixed» closed
 
 

Drupal is a registered trademark of Dries Buytaert.