'hook_nodeapi' use

Last week we had a release for one of our clients. The day before the release I decided to check the query log. On the front page eleven nodes were loaded which resulted in 99 queries! This made me investigate further. The problem is that some modules are using a query in 'hook_nodeapi' on the 'load' operator, even though the queried information was not relevant. The following modules allow a quick fix:

Book

Book information is always loaded. Even though in drupal 5 the node type should be 'book' and in 6 and 7 the node type should be in the variable 'book_allowed_types'. A patch for 7-dev was submitted and committed. For 6 a backport has been supplied. For 5 a different solution was submitted but has not been reviewed yet.

Comment

In comment 'hook_nodeapi' loads “last_comment_timestamp, last_comment_name, comment_count” even when comments are off. A patch was submitted limiting comment information based on node type. Damien Tournoud correctly pointed out comment is not a node type setting but a node setting. A new patch was submitted limiting loading if commenting is on for a node. The patch has been reviewed and tested but still has to be submitted.

E-commerce

A node can be a product. For the 3.4 version you can register your node-type with e-commerce. The nodeapi load however always tries to load product information. A patch was submitted to limit the load only when the node type is registered. Because the 4.0-alpha11 uses a different method for registering node types some more work is needed.

Scheduler

Scheduling can be turned on/off for each node type. This module however always loaded scheduler information. A patch was submitted and committed adding a check or the node type has scheduling turned on.

Conclusion

As you can see a lot of modules (even core) try to load information which is never available. 'hook_nodeapi' is very powerful but the 'load' operator should be handled with care because it is executed for every loaded node.

Some other issues which were found

Comment patch comitted

The patch provided for comment has also been comitted.

Thanks for the great work on

Thanks for the great work on this, and the important reminder for other developers. That's the kind of detail that's easy to overlook sometimes, but can make or break the performance of a module.

Aaron Winborn
http://aaronwinborn.com/