In function _menu_link_build($item) this code is sub-optimal:
...
$placeholders = implode(', ', array_fill(0, count($menu), "'%s'"));
// Remove items if their router path does not exist any more.
db_query('DELETE FROM {menu_links} WHERE router_path NOT IN ('. $placeholders .')', array_keys($menu));
since it doesn't use the API function, it's possible we'll have orphaned links. It should probably be something like:
...
$placeholders = implode(', ', array_fill(0, count($menu), "'%s'"));
// Remove items if their router path does not exist any more.
$result = db_query('SELECT mlid FROM {menu_links} WHERE router_path NOT IN ('. $placeholders .')', array_keys($menu));
while ($m = db_fetch_array($result)) {
menu_link_delete($m['mlid']);
}
but a patch needs to wait for: http://drupal.org/node/151583
Comments
Comment #1
pwolanin commentedA related bug whose fix should be included with this patch: http://drupal.org/node/166336
Comment #2
pwolanin commentedperhaps this LEFT JOIN will be faster?
Comment #3
pwolanin commentedHere's a patch back to the original form of the query. It's not really clear to me which is better (either works): here are the MySQL explain results (the 202 unique router paths omitted for clarity) :
I'm guessing that the first (the one used in this patch) may be faster since it has the possibility of using a key (though it doesn't in this case) and it only operates on a single table. Since this is a rare operation, speed isn't critical.
Comment #4
chx commentedCode is OK and does what it needs to do. I think it's good to go.
Comment #5
dries commentedCommitted to CVS HEAD. Thanks.
Comment #6
pwolanin commentedcrud - apparently I am too smart for myself and didn't test this thoroughly enough.
We have as a safety check in function _menu_delete_item():
So, our safety check defeats our intent to use the API function and the code code in menu.inc leaves behind any system-created links.
Further fix attached - adds a "rebuild" flag to function _menu_delete_item() to indicate that we are doing a menu rebuild and should bypass this safety check (and also bypass clearing the menu cache, since it's already cleared).
Comment #7
webernet commentedTested and looks OK.
Comment #8
gábor hojtsyCommitted to Drupal 6, thanks.
Comment #9
(not verified) commented