[development] The new menu system

Earl Miles merlin at logrus.com
Thu Sep 28 12:37:08 UTC 2006

Larry Garfield wrote:
> So then, you'd generate all interpolations of an incoming path (above), then 
> loop and do an isset() on the cached menu array for the path?  Something like 
> that?

Better. Create all possible variants on the current URL, do a fetch from 
the menu table using an IN, and ORDER the query by the weight 
descending, so the highest comes to the top. Then take the first result 
that comes up.

For example:

The actual URL entered is: node/12/edit/foo

the simplistic version of the query would be:

SELECT * FROM menu WHERE path IN ('node/12/edit/foo', 'node/12/edit', 
'node/12/%/foo', 'node/%/edit/foo', 'node/%/%/foo', 'node/%/edit', 
'node/%') ORDER BY weight DESC;

This does have an order of N complexity in that there are 2^N-1 URL 
possibilities for every URL fragment you have -- which gets unwieldy 
around 7, but it is rare that you get URLs that long, though I imagine 
it does happen from time to time. At this time we believe this is an 
acceptable cost compared to the cost of the system it is replacing, 
while leaving us with maximum flexibility.

More information about the development mailing list