I have found that function nodeorder_can_be_ordered() calls many times and always do the equal SQL query.
For example, in my site this function adds 20 equal SQL queries for each page load!
We can cache the result by using static variable.
I have change function nodeorder_can_be_ordered() from

 function nodeorder_can_be_ordered($node) {
  $sql = "SELECT v.vid AS vid FROM {vocabulary_node_types} vnt JOIN {vocabulary} v ON vnt.vid = v.vid WHERE vnt.type = '%s' AND v.module = 'nodeorder'";
  $result = db_query($sql, $node->type);
  
  if (db_num_rows($result)) {
    return TRUE;
  }
  
  return FALSE;
} 

to

 function nodeorder_can_be_ordered($node) {
  static $can_ordered=array();
  if(isset($can_ordered[$node->type])) return $can_ordered[$node->type];
  $sql = "SELECT v.vid AS vid FROM {vocabulary_node_types} vnt JOIN {vocabulary} v ON vnt.vid = v.vid WHERE vnt.type = '%s' AND v.module = 'nodeorder'";
  $result = db_query($sql, $node->type);
  
  if (db_num_rows($result)) {
    return $can_ordered[$node->type]=TRUE;
  }
  
  return $can_ordered[$node->type]=FALSE;
} 

This manipulation reduce equal queries from 20 to 1!

Comments

marcp’s picture

Version: 5.x-1.2 » master
Assigned: Unassigned » pvanderspek

This is a great idea. We need to figure out why nodeorder_can_be_ordered() is called so often to start with. I suspect, in the 6.x version, this isn't as big of an issue any more because we used to call nodeorder_can_be_ordered() in hook_nodeapi() regardless of the operation, so it was getting called on every page view.

It may be worthwhile to backport this change to 5.x also.

pvanderspek’s picture

Version: master » 6.x-1.x-dev
Status: Needs review » Fixed

This has been fixed in the 6.x version by using the Drupal caching mechanism. These values will not change frequently so caching is better than a static variable.

Status: Fixed » Closed (fixed)

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