Hi,
I found a performance leak if the topic navigation feature is enabled, but I found the solution to this leak.

What are the steps required to reproduce the bug?
We can easily reproduce the bug because on our site we have forum with almost 10000 topics (nodes). And the leak is the worst when I select the last topic (node) in forum.

What behavior were you expecting?
I think that the code have to calculate the previous link and the next link only when it finds the selected topic (node) and not for each topic (node) in forum.

What happened instead?
At the moment the code calculates the previous link and the next link for each topic (node) in forum. To calculate the link, the code uses the url(...) function which in this case is very expensive because if I select the last topic (node) in forum then the code calls 10000 times the drupal_get_path_alias function.

I modified the code of template_preprocess_forum_topic_navigation like follow:

function template_preprocess_forum_topic_navigation(&$variables) {
  $output = '';

  // get previous and next topic
  $sql = "SELECT n.nid, n.title, n.sticky, l.comment_count, l.last_comment_timestamp FROM {node} n INNER JOIN {node_comment_statistics} l ON n.nid = l.nid INNER JOIN {term_node} r ON n.nid = r.nid AND r.tid = %d WHERE n.status = 1 ORDER BY n.sticky DESC, ". _forum_get_topic_order_sql(variable_get('forum_order', 1));
  $result = db_query(db_rewrite_sql($sql), isset($variables['node']->tid) ? $variables['node']->tid : 0);

  $stop = $variables['prev'] = $variables['next'] = 0;
  $topic0 = $topic1 = FALSE;

  while ($topic = db_fetch_object($result)) {
  	$topic1 = $topic0;
  	$topic0 = $topic;
    if ($stop == 1) {
      $variables['next'] = $topic->nid;
      $variables['next_title'] = check_plain($topic->title);
      $variables['next_url'] = url("node/$topic->nid");
      break;
    }
    if ($topic->nid == $variables['node']->nid) {
      $stop = 1;
      if ($topic1) {
	      $variables['prev'] = $topic1->nid;
	      $variables['prev_title'] = check_plain($topic1->title);
	      $variables['prev_url'] = url("node/$topic1->nid");
      }
    }
  }
}

As you can see I call the url(...) function only when I have found the node selected because I mantain the referement to the previous node for each cicle.

With this code the performance are much improved. But I would like to have this code on Drupal release in order to have a clean release on my project.

I discovered this leak thanks to XDebug.

Thanks in advance.

Pier Paolo

Let

Comments

michelle’s picture

FWIW, the topic navigation has been removed by Drupal 7 and is made optional by Advanced Forum in D6. I don't know if this fix will get into D6 because of that but it's not my call. I'll have to take a closer look... If it's really an improvement, I'll add it to Advanced Forum.

Michelle

niteman’s picture

suscribing

larowlan’s picture

Version: 6.19 » 6.22

Please submit a patch file

larowlan’s picture

Status: Active » Needs work

Status: Needs work » Closed (outdated)

Automatically closed because Drupal 6 is no longer supported. If the issue verifiably applies to later versions, please reopen with details and update the version.