In your node_load you do this:

function scheduler_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {

  // Run $op == load for any user.
  if ($op == 'load') {
    if (isset($node->nid) && $node->nid) {
      $result = db_query('SELECT * FROM {scheduler} WHERE nid = %d', $node->nid);
      if ($result) {
        $row = db_fetch_array($result);
        if (isset($row['nid'])) {
          unset($row['nid']);
          $node->publish_on = $row['publish_on'];
          $node->unpublish_on = $row['unpublish_on'];
          $node->timezone = $row['timezone'];
          $row['published'] = $row['publish_on'] ? date(variable_get('date_format_long', 'l, F j, Y - H:i'), $row['publish_on']) : NULL;
          $row['unpublished'] = $row['unpublish_on'] ? date(variable_get('date_format_long', 'l, F j, Y - H:i'), $row['unpublish_on']) : NULL;
          $node->scheduler = $row;
        }
      }
    }
  }

So every node_load a query is done whether or not that node type can have scheduler information. In your form_alter you have this (line 67):

if (variable_get('scheduler_'. $form['type']['#value'], 0) == 1) {

Why not do this for your nodeapi load too so you don't make unnecessary queries. Please change it to this:

function scheduler_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {

  // Run $op == load for any user.
  if ($op == 'load') {
    if (isset($node->nid) && $node->nid && variable_get('scheduler_'. $node->type, 0) == 1) {
      $result = db_query('SELECT * FROM {scheduler} WHERE nid = %d', $node->nid);
      if ($result) {
        $row = db_fetch_array($result);
        if (isset($row['nid'])) {
          unset($row['nid']);
          $node->publish_on = $row['publish_on'];
          $node->unpublish_on = $row['unpublish_on'];
          $node->timezone = $row['timezone'];
          $row['published'] = $row['publish_on'] ? date(variable_get('date_format_long', 'l, F j, Y - H:i'), $row['publish_on']) : NULL;
          $row['unpublished'] = $row['unpublish_on'] ? date(variable_get('date_format_long', 'l, F j, Y - H:i'), $row['unpublish_on']) : NULL;
          $node->scheduler = $row;
        }
      }
    }
  }

Applies to the 6.X-1.1 version too

CommentFileSizeAuthor
scheduler_nodeapi_load.patch527 bytesR.Muilwijk

Comments

skiminki’s picture

Version: » 5.x-1.13-rc1
Status: Needs review » Fixed

Ok, this patch seems valid. After some consideration, I'm going to include this into 1.13, even if this doesn't fix an actual bug and it's only a minor performance enhancement.

Note!
After this patch, scheduler fields are not loaded into node anymore if the scheduler is not enabled for node's content type.

http://drupal.org/cvs?commit=112873

I'll create a separate issue for Drupal 6.

R.Muilwijk’s picture

Thank you,
lots of people always load in nodeapi (check core issue: http://drupal.org/node/250729)

It does save alot of queries on like Views table pages and forums (for every node a node_load!!!)

skiminki’s picture

Status: Fixed » Closed (fixed)

In 5.x-1.13.