{"action":"closed","issue":{"url":"https://api.github.com/repos/backdrop/backdrop-issues/issues/1810","repository_url":"https://api.github.com/repos/backdrop/backdrop-issues","labels_url":"https://api.github.com/repos/backdrop/backdrop-issues/issues/1810/labels{/name}","comments_url":"https://api.github.com/repos/backdrop/backdrop-issues/issues/1810/comments","events_url":"https://api.github.com/repos/backdrop/backdrop-issues/issues/1810/events","html_url":"https://github.com/backdrop/backdrop-issues/issues/1810","id":150239045,"number":1810,"title":"Main menu unnecessarily checks access on hidden links","user":{"login":"quicksketch","id":100206,"avatar_url":"https://avatars.githubusercontent.com/u/100206?v=3","gravatar_id":"","url":"https://api.github.com/users/quicksketch","html_url":"https://github.com/quicksketch","followers_url":"https://api.github.com/users/quicksketch/followers","following_url":"https://api.github.com/users/quicksketch/following{/other_user}","gists_url":"https://api.github.com/users/quicksketch/gists{/gist_id}","starred_url":"https://api.github.com/users/quicksketch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/quicksketch/subscriptions","organizations_url":"https://api.github.com/users/quicksketch/orgs","repos_url":"https://api.github.com/users/quicksketch/repos","events_url":"https://api.github.com/users/quicksketch/events{/privacy}","received_events_url":"https://api.github.com/users/quicksketch/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/backdrop/backdrop-issues/labels/docs%20-%20needs%20change%20record","name":"docs - needs change record","color":"fad8c7"},{"url":"https://api.github.com/repos/backdrop/backdrop-issues/labels/type%20-%20bug%20report","name":"type - bug report","color":"fc2929"}],"state":"closed","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/backdrop/backdrop-issues/milestones/20","html_url":"https://github.com/backdrop/backdrop-issues/milestones/1.4.0","labels_url":"https://api.github.com/repos/backdrop/backdrop-issues/milestones/20/labels","id":1398592,"number":20,"title":"1.4.0","description":"1.4.0","creator":{"login":"jenlampton","id":397895,"avatar_url":"https://avatars.githubusercontent.com/u/397895?v=3","gravatar_id":"","url":"https://api.github.com/users/jenlampton","html_url":"https://github.com/jenlampton","followers_url":"https://api.github.com/users/jenlampton/followers","following_url":"https://api.github.com/users/jenlampton/following{/other_user}","gists_url":"https://api.github.com/users/jenlampton/gists{/gist_id}","starred_url":"https://api.github.com/users/jenlampton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jenlampton/subscriptions","organizations_url":"https://api.github.com/users/jenlampton/orgs","repos_url":"https://api.github.com/users/jenlampton/repos","events_url":"https://api.github.com/users/jenlampton/events{/privacy}","received_events_url":"https://api.github.com/users/jenlampton/received_events","type":"User","site_admin":false},"open_issues":12,"closed_issues":19,"state":"open","created_at":"2015-11-06T22:11:56Z","updated_at":"2016-05-15T05:47:55Z","due_on":"2016-05-15T07:00:00Z","closed_at":null},"comments":3,"created_at":"2016-04-22T01:33:54Z","updated_at":"2016-05-15T05:47:55Z","closed_at":"2016-05-15T05:47:55Z","body":"Whenever the main menu is shown (every front-end page of the site by default), access is checked on every link in the menu to determine if it should be shown or not.\r\n\r\nThis functionality is expected, but what is surprising is that the main menu contains dozens of \"hidden\" links, on which ~~access is checked~~ processing is done every page load. Doing a query in MySQL shows these items:\r\n\r\n```\r\nmysql> select * from menu_links where menu_name = 'main-menu`;\r\n+-----------+------+------+------------------------------+\r\n| menu_name | mlid | plid | link_path                    |\r\n+-----------+------+------+------------------------------+\r\n| main-menu |   20 |    0 | comment/reply/%              |\r\n| main-menu |   22 |    0 | filter/tips/%                |\r\n| main-menu |  142 |    0 | search                       |\r\n| main-menu |  145 |    0 | taxonomy/term/%              |\r\n| main-menu |  211 |    0 | <front>                      |\r\n| main-menu |  394 |    0 | node/%                       |\r\n| main-menu |    3 |    0 | comment/%                    |\r\n| main-menu |   21 |    3 | comment/%/approve            |\r\n| main-menu |   23 |    3 | comment/%/delete             |\r\n| main-menu |   24 |    3 | comment/%/edit               |\r\n| main-menu |   25 |    3 | comment/%/view               |\r\n| main-menu |  264 |    3 | comment/%/devel              |\r\n| main-menu |  143 |  142 | search/node                  |\r\n| main-menu |  144 |  142 | search/user                  |\r\n| main-menu |  146 |  143 | search/node/%                |\r\n| main-menu |  150 |  144 | search/user/%                |\r\n| main-menu |  153 |  145 | taxonomy/term/%/delete       |\r\n| main-menu |  154 |  145 | taxonomy/term/%/edit         |\r\n| main-menu |  155 |  145 | taxonomy/term/%/view         |\r\n| main-menu |  273 |  145 | taxonomy/term/%/devel        |\r\n| main-menu |  275 |  264 | comment/%/devel/load         |\r\n| main-menu |  278 |  264 | comment/%/devel/render       |\r\n| main-menu |  281 |  273 | taxonomy/term/%/devel/load   |\r\n| main-menu |  282 |  273 | taxonomy/term/%/devel/render |\r\n| main-menu |  396 |  394 | node/%/delete                |\r\n| main-menu |  397 |  394 | node/%/devel                 |\r\n| main-menu |  398 |  394 | node/%/edit                  |\r\n| main-menu |  402 |  394 | node/%/view                  |\r\n| main-menu |  401 |  394 | node/%/revisions             |\r\n| main-menu |  403 |  397 | node/%/devel/load            |\r\n| main-menu |  404 |  397 | node/%/devel/render          |\r\n| main-menu |  405 |  401 | node/%/revisions/%/delete    |\r\n| main-menu |  406 |  401 | node/%/revisions/%/revert    |\r\n| main-menu |  407 |  401 | node/%/revisions/%/view      |\r\n+-----------+------+------+------------------------------+\r\n34 rows in set (0.00 sec)\r\n```\r\n\r\nAlthough `menu_build_tree()` caches the SELECT statement from the database, `menu_tree_check_access()` is called on each item every page load.\r\n\r\nThe cause of this is that menu items default to saving items into the main menu, even if they contain wildcards like `node/%`, which can't be shown in the menu anyway. It's also odd that sub-menu items like `search/node` have their access checked, when at most `search` would ever be shown.\r\n\r\nWhat I'd like propose is that instead of defaulting items to `main-menu` in `hook_menu()`, we make a new separate menu that is used just for internal link tracking. This menu can't actually be shown as a block, but it may be used to keep track of hierarchical relationships such as menu local tasks and actions. This keeps our functionality unchanged while saving the main menu block from needing to load and check access on these items that will never be shown in the first place."}}