- Slightly modified the API of node_title_list(): it will no longer call comment_num_all() for each node. Instead, it checks for the availability of the node_comment field, available through the node_comment_statistics table. If updated the Doxygen comments accordingly.

People were using node_title_list() without realizing it would do numereous database queries.  This change greatly reduces the number of database queries required to render the node statistics block as well as to render the forum block (coming up next).

  If your module is using node_title_list() and you want the number of comments to be shown as title attributes, chances are you have to update your SQL query to join node_comment_statistics.
4.6.x
Dries Buytaert 2004-11-04 21:02:30 +00:00
parent 7ad36e3f59
commit 14353d18ad
2 changed files with 6 additions and 6 deletions

View File

@ -75,7 +75,8 @@ function node_help_page() {
* Gather a listing of links to nodes.
*
* @param $result
* A DB result object from a query to fetch node objects.
* A DB result object from a query to fetch node objects. If your query joins the <code>node_comment_statistics</code> table so that the <code>comment_count</code> field is available, a title attribute will be added to show the number of comments.
* field to be set.
* @param $title
* A heading for the resulting list.
*
@ -84,8 +85,7 @@ function node_help_page() {
*/
function node_title_list($result, $title = NULL) {
while ($node = db_fetch_object($result)) {
$number = module_invoke('comment', 'num_all', $node->nid);
$items[] = l($node->title, 'node/'. $node->nid, $number ? array('title' => format_plural($number, '1 comment', '%count comments')) : '');
$items[] = l($node->title, 'node/'. $node->nid, $node->comment_count ? array('title' => format_plural($node->comment_count, '1 comment', '%count comments')) : '');
}
return theme('node_list', $items, $title);

View File

@ -75,7 +75,8 @@ function node_help_page() {
* Gather a listing of links to nodes.
*
* @param $result
* A DB result object from a query to fetch node objects.
* A DB result object from a query to fetch node objects. If your query joins the <code>node_comment_statistics</code> table so that the <code>comment_count</code> field is available, a title attribute will be added to show the number of comments.
* field to be set.
* @param $title
* A heading for the resulting list.
*
@ -84,8 +85,7 @@ function node_help_page() {
*/
function node_title_list($result, $title = NULL) {
while ($node = db_fetch_object($result)) {
$number = module_invoke('comment', 'num_all', $node->nid);
$items[] = l($node->title, 'node/'. $node->nid, $number ? array('title' => format_plural($number, '1 comment', '%count comments')) : '');
$items[] = l($node->title, 'node/'. $node->nid, $node->comment_count ? array('title' => format_plural($node->comment_count, '1 comment', '%count comments')) : '');
}
return theme('node_list', $items, $title);