Closed (fixed)
Project:
Scheduler
Version:
5.x-1.13-rc1
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
25 Apr 2008 at 09:55 UTC
Updated:
28 Apr 2008 at 13:16 UTC
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
| Comment | File | Size | Author |
|---|---|---|---|
| scheduler_nodeapi_load.patch | 527 bytes | R.Muilwijk |
Comments
Comment #1
skiminki commentedOk, 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.
Comment #2
R.Muilwijk commentedThank 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!!!)
Comment #3
skiminki commentedIn 5.x-1.13.