$alias = drupal_get_path_alias('node/' . $comment->nid);
  $node = node_load($comment->nid);
  $page = comment_get_display_page($comment->cid, $node->type);
  
  if ($page > 0) {
    if ($alias != $current_path) {
      return array(
        'path' => drupal_get_path_alias('node/' . $comment->nid),
        'options' => array('fragment' => 'comment-' . $comment->cid, 'query' => array('page' => $page)),
      );
    }

drupal_get_path_alias() is called further up. Surely it doesn't need to be called again (several times) further on, as the parameters are the same.

CommentFileSizeAuthor
#2 2227073.diff2.72 KBdrumm

Comments

danpros’s picture

Hi joachim,

Thanks for pointing it out :) yup it will save many unneeded DB query.

drumm’s picture

Title: repeated calls to drupal_get_path_alias() » Remove calls to drupal_get_path_alias()
Assigned: Unassigned » drumm
Status: Active » Needs review
Issue tags: +affects drupal.org
StatusFileSize
new2.72 KB

Actually, we don't even need to call it at all. The path goes through url() on the way to rendering, which does path lookups. The attached patch simplifies the code quite a bit knowing this, and clean up some whitespace.

This can trigger #1200478: Changing the comment path to the node path triggers a PHP fatal error in l() due to wrongly structured options.

sun’s picture

Status: Needs review » Reviewed & tested by the community

Looks great to me. And indeed, manually retrieving the alias is unnecessary, since l() already performs aliasing.

danpros’s picture

I already add @drumm as the maintainer.

Currently I have 52138 comments from 5635 nodes on the site (the demo link) so I can use it to test it.

Note: let me know if anyone need maintainer role on this project.

  • Commit 2bb703a on 7.x-1.x by drumm:
    #2227073 Remove calls to drupal_get_path_alias()
    
drumm’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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