Drupal's regular menu system administration doesn't scale very well. This is due to the fact that for all node edit pages, node type edit pages and vocabulary edit pages (when Taxonomy Menu is active), Drupal loads all menu items from all menus in the system. For large amount of menu items, this slows down the system to an unusably slow speed, or even causes timouts.

This is a known problem in Drupal core. This comment is from the menu module:

  // The menu_links table can be practically any size and we need a way to
  // allow contrib modules to provide more scalable pattern choosers.
  // hook_form_alter is too late in itself because all the possible parents are
  // retrieved here, unless menu_override_parent_selector is set to TRUE.
  if (variable_get('menu_override_parent_selector', FALSE)) {
    return array();
  }

Menuperformance takes advantage of this, and sets the variable when installed. It then proceeds to add its own AJAX based parent menu item selector widgets for the node edit, node type edit and vocabulary edit pages.

http://drupal.org/sandbox/firebird/1403852
http://git.drupal.org/sandbox/firebird/1403852.git

This is a Drupal 7 module.

Reviews of other projects:

http://drupal.org/node/1403766#comment-5805046
http://drupal.org/node/1176740#comment-5805010
http://drupal.org/node/1488834#comment-5804686
http://drupal.org/node/1336934#comment-5804640

CommentFileSizeAuthor
#2 drupalcs-result.txt3.01 KBklausi

Comments

firebird’s picture

Status: Active » Needs review
klausi’s picture

Category: feature » task
Status: Needs review » Needs work
StatusFileSize
new3.01 KB

It appears you are working in the "master" branch in git. You should really be working in a version specific branch. The most direct documentation on this is Moving from a master branch to a version branch. For additional resources please see the documentation about release naming conventions and creating a branch in git.
Review of the master branch:

This automated report was generated with PAReview.sh, your friendly project application review script. You can also use the online version to check your project. Go and review some other project applications, so we can get back to yours sooner.

manual review:

  • menuperformance_install(): this is a hook implementation and needs to be documented as such, see http://drupal.org/node/1354#hookimpl
  • menuperformance_install(): instead of juggling with unstable module weights you can make use of hook_module_implements_alter() the re-arrange the hook execution order of modules.
  • "'#title' => 'Parent item',": make sure to raun all user facing text through t() for translation.
  • do not use drupal_add_js() and drupal_add_css() in hook_form_alter(), use $form['#attached'] instead. See http://api.drupal.org/api/drupal/developer--topics--forms_api_reference....
  • "form_set_error('menu][parent', 'Invalid parent menu string. Format should be "MENUNAME:MLID".');": again, this should be translated. Check all strings in your module.
  • menuperformance_ajax(): do not use die() here, use drupal_json_output() and drupal_exit().
  • menuperformance_get_link_children(): "@param String $menu_name": String should be lower case, description should be on the next line. And the function doc block should contain a short description on the first line.
firebird’s picture

Thanks for the feedback. I probably won't have time to work on this in the next couple of months, but I will get back into it.

firebird’s picture

Status: Needs work » Needs review

I think I've covered all the things mentioned in the above post by klausi.

Please review again.

firebird’s picture

Issue summary: View changes

Added D7

firebird’s picture

Issue tags: +PAreview: review bonus

Added PAReview review bonus tag.

targoo’s picture

Status: Needs review » Needs work

Hi

1) menuperformance.install

Your install file is empty. If you don't need it you can remove it.

2) menuperformance.js
As of jQuery 1.7, the .live() method is deprecated. Use .on() to attach event handlers.
See http://api.jquery.com/on/

3) menuperformance.module
t() is not needed for hook_menu in title and description.

4) menuperformance.module
FAPI will NOT sanitize the '#options' attribute on other elements than select boxes. Could open up XSS exploits as the menu could be create by users.

418 $form['menu']['menu_options'] = array(
419 '#type' => 'checkboxes',
420 '#title' => t('Available menus'),
421 '#default_value' => variable_get('menu_options_' . $type->type, array('main-menu')),
422 '#options' => $menu_options,
423 '#description' => t('The menus available to place links in for this content type.'),
424 );

Please check http://drupal.org/node/28984

Thanks,

firebird’s picture

Status: Needs work » Needs review

1. Empty install file removed

2. Since Drupal currently ships with jQuery 1.4.4, I've changed the javascript to use delegate() instead. jQuery 1.4.4 doesn't have on().

3. t() calls removed from menu hook.

4. This form alter hook is directly copied from the core menu module, so I figured it would be safe. I tried adding a script tag in the menu name, and it does get stripped out before it's printed. This in done in theme_form_element_label() with a call to filter_xss_admin(). Maybe the documentation that says the values don't get filtered is out of date?

sankatha’s picture

Status: Needs review » Needs work
Issue tags: -PAreview: review bonus

Tested this and found the following bug. Steps to reproduce is as follows. The test was done on a clean Drupal 7.12 installation.

  1. Login as admin and enable the module according to the instructions in the README.txt
  2. Go to Content > Add content > Basic Page
  3. Add a title as "Test Bug" and the body of the content type Basic Page
  4. Goto Menu Settings and click on the Provide a menu link check box in the node edit/create page
  5. Select "Main menu from the parent item" and save/create the node
  6. Now click on the edit tab on the created node again
  7. Go to the Menu setting section and select 'Test Bug' Menu item from the second drop down list (child menu list) of the Parent item fieldset and save the node again.
  8. Now click on the edit tab again and you can see plenty of child item select boxes has been generated for no reason.

Also I can see why you display the menu mlid before the Parent Item select box but personally think that you should not call two form elements by a same name/title (in this case 'Parent item') because this will be confusing to the end user in a UX perspective. Also removing the PAReview: review bonus tag as you can get it back by reviewing another three issues in the application queue.

klausi’s picture

@firebird: You are actually right about the security issue, it is not necessary to sanitize #options for checkboxes and radios in Drupal 7 anymore. Thank you for pointing that out, I have updated the documentation page to address that. http://drupal.org/node/28984

That's why I love this review process, always learning something new about Drupal :-)

firebird’s picture

Status: Needs work » Needs review

@sankatha: Good catch. Setting a menu item as its own parent was bound to cause trouble...

I've added checks to prevent that, and I've also removed the menu item from a list of its own possible parents. This did require some refactoring of the code, so there may be new bugs introduced.

Ventral.org's online PAReview seems to be down right now, so there may be some coding standard issues. Coder-module didn't find anything, though.

seyv’s picture

For the record:
No coding standard issues can be found by Ventral.org's online PAReview http://ventral.org/pareview/httpgitdrupalorgsandboxfirebird1403852git

Please update your direct link to your git repository. Will make all of our lives easier.
Despite the code refactoring, I can't find any bugs so kudos ;)

+1

seyv’s picture

Issue summary: View changes

Added links to reviewed projects

frob’s picture

Status: Needs review » Needs work

Couple of quick notes,

There is an error in your README.txt file. Your how to use directions say to go to /config/user-interface/menuperformance it should be admin/config/user-interface/menuperformance

I would also recommend putting this link and information into a drupal_set_message when the module is enabled. Not everyone reads the README.txt until something goes wrong. It does help to have a "how to test" section in the issue summery.

Also your README isn't formatted correctly. A couple of the lines end on the first letter. I like to give short words a little bit more of a buffer (78 chars wide) to help people who use vi and the console.

On the bright side it does pass PAReview with no errors and it works. I installed with no real issues (just not knowing why it wasn't working till I read the README.txt) and I like the concept.

firebird’s picture

Status: Needs work » Needs review

Fixed. Not that I think a misformatted README file should prevent a project from being assigned full project status... ;)

I also added the notification you suggested, good idea.

frob’s picture

Status: Needs review » Needs work

Automated review issues:
Review of the 7.x-1.x branch:

This automated report was generated with PAReview.sh, your friendly project application review script. You can also use the online version to check your project. Get a review bonus and we will come back to your application sooner.

Severity minor, Drupal Commenting Standards, Internationalization, Drupal Security Checks, Drupal SQL Standards, Drupal Coding Standards

sites/all/modules/pareview_temp/./test_candidate/menuperformance.install:
 +12: [normal] The $message argument to drupal_set_message() should be enclosed within t() so that it is translatable.
 +12: [critical] Potential problem: drupal_set_message() only accepts filtered text, be sure to use check_plain(), filter_xss() or similar to ensure your $variable is fully sanitized.

Status Messages:
 Coder found 1 projects, 1 files, 1 critical warnings, 1 normal warnings, 0 warnings were flagged to be ignored

Source: http://ventral.org/pareview - PAReview.sh online service

Fix this and I will rtbc, the issue wasn't so much the misformed README.txt file as much as it was the wrong url in the README.txt file.

firebird’s picture

Status: Needs work » Needs review

Added filter_xss() and t(), checked with PAReview again.

Thanks for reviewing!

lawik’s picture

Status: Needs review » Reviewed & tested by the community

The filter_xss() and t() is there. Marking rtbc.

patrickd’s picture

Assigned: Unassigned » patrickd
patrickd’s picture

Status: Fixed » Reviewed & tested by the community
  1. As installation and usage instructions are quite important for us to review, please take a moment to make your project page follow the tips for a great project page. Also make sure your README.txt follows the guidelines for in-project documentation.
  2. The error about the possible security issue (mentioned in #14) is a false positive - don't trust these automated reports too much ! they're pretty dumb when detecting possible security issues!drupal_set_message(filter_xss(t('Menuperformance module activated. To take the module into use, <a href="@baseurl/admin/config/user-interface/menuperformance">go to the settings page</a> and check the checkbox.', array('@baseurl' => $base_url))));
    It makes no sense to add both, t() and filter_xss() as t() already filters all used variables (prefixed with @ or %) and the text your filtering is static => contains no user input and is therefore harmless.
    Also there's no need to add the @baseurl to the path - but you have to put the path though url().drupal_set_message(t('Menuperformance module activated. To take the module into use, <a href="!url">go to the settings page</a> and check the checkbox.', array('!url' => url('admin/config/user-interface/menuperformance'))));
  3. You've got a settings page -> add it with "configure = " to your .info
  4. please put a newline in the comment block between "implements.. " and the documentation what it's good for
  5. if possible you should rather use the "weight" field in the system table to control in which order hooks should be implemented instead of using "hook_module_implements_alter()" which is more performance intensive
  6. wouldn't it make sense to reset the "menu_override_parent_selector" variable to FALSE when disabling the module ?

Anyways, there are a lot of TODO's marked, also related with access checking, you really should resolve these issues before thinking about creating a release. Also don't show developer information to normal users (you probably planned to remove that anyway) but a debug mode is always good ^^

Beside that I think you know what your doing and I like how detailed your documenting your code inline ;)

Thanks for your contribution and welcome to the community of project contributors on drupal.org.

I've granted you the git vetted user role which will let you promote this to a full project and also create new projects as either sandbox or "full" projects depending on which you feel is best.

Thanks, also, for your patience with the review process and for your help in the queue! Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review. I encourage you to learn more about that process and join the group of reviewers.

As you continue to work on your module, keep in mind: Commit messages - providing history and credit and Release naming conventions.

Thanks to the dedicated reviewer(s) as well.

patrickd’s picture

Status: Reviewed & tested by the community » Fixed
klausi’s picture

One correction to #5 in Patrick's review: it is quite the opposite: do not juggle with module weights where possible, as this is unreliable and unpredictable. Hooks are cached, so there is no performance penalty for using hook_module_implements_alter().

patrickd’s picture

Ohkay, good point! (shit I've got to patch my modules...)
thanks :)

firebird’s picture

Status: Reviewed & tested by the community » Fixed

Thanks to all the reviewers! I've promoted the project, and will do the first release in a few moments.

In response to patrickd's comments:
1) I've improved the project page and the readme file.
2) Changed the line generating the message as per the suggestion.
3) Added the settings page to the info file.
4) Added a newline.
5) Ignored.
6) I didn't do this, since it's not Menuperformance that defines the variable. The separate activation checkbox is there for the same reason.

I've also gone through my TODOs, added necessary access checks, and done the TODOs, apart from one, which I added as a feature request in the projects issue queue.

Status: Fixed » Closed (fixed)

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

Anonymous’s picture

Issue summary: View changes

Added direct git link