? modules/database.mysql Index: modules/forum.module =================================================================== RCS file: /cvs/drupal/drupal/modules/forum.module,v retrieving revision 1.336 diff -u -p -r1.336 forum.module --- modules/forum.module 5 Jul 2006 11:45:51 -0000 1.336 +++ modules/forum.module 7 Jul 2006 14:33:32 -0000 @@ -255,6 +255,7 @@ function forum_block($op = 'list', $delt case 'save': variable_set('forum_block_num_'. $delta, $edit['forum_block_num_'. $delta]); + cache_clear_all("block:forum:$delta:", TRUE); break; case 'view': @@ -262,20 +263,48 @@ function forum_block($op = 'list', $delt switch ($delta) { case 0: $title = t('Active forum topics'); - $sql = db_rewrite_sql("SELECT n.nid, n.title, l.comment_count FROM {node} n INNER JOIN {node_comment_statistics} l ON n.nid = l.nid WHERE n.status = 1 AND n.type = 'forum' ORDER BY l.last_comment_timestamp DESC"); - $result = db_query_range($sql, 0, variable_get('forum_block_num_0', '5')); - if (db_num_rows($result)) { - $content = node_title_list($result); + if (node_access_usage()) { + global $user; + $cache_id = "block:forum:0:$user->uid"; } + else { + $cache_id = 'block:forum:0:'; + } + if ($cache = cache_get($cache_id)) { + $items = unserialize ($cache->data); + } + else { + $sql = db_rewrite_sql("SELECT n.nid, n.title, l.comment_count FROM {node} n INNER JOIN {node_comment_statistics} l ON n.nid = l.nid WHERE n.status = 1 AND n.type = 'forum' ORDER BY l.last_comment_timestamp DESC"); + $result = db_query_range($sql, 0, variable_get('forum_block_num_0', '5')); + if (db_num_rows($result)) { + $items = node_title_list($result); + } + cache_set($cache_id, serialize($items), time() + (60 * 60 * 24)); + } + $content = theme('node_list', $items, $title); break; case 1: $title = t('New forum topics'); - $sql = db_rewrite_sql("SELECT n.nid, n.title, l.comment_count FROM {node} n INNER JOIN {node_comment_statistics} l ON n.nid = l.nid WHERE n.type = 'forum' AND n.status = 1 ORDER BY n.nid DESC"); - $result = db_query_range($sql, 0, variable_get('forum_block_num_1', '5')); - if (db_num_rows($result)) { - $content = node_title_list($result); + if (node_access_usage()) { + global $user; + $cache_id = "block:forum:1:$user->uid"; + } + else { + $cache_id = 'block:forum:1:'; + } + if ($cache = cache_get($cache_id)) { + $items = unserialize ($cache->data); + } + else { + $sql = db_rewrite_sql("SELECT n.nid, n.title, l.comment_count FROM {node} n INNER JOIN {node_comment_statistics} l ON n.nid = l.nid WHERE n.type = 'forum' AND n.status = 1 ORDER BY n.nid DESC"); + $result = db_query_range($sql, 0, variable_get('forum_block_num_1', '5')); + if (db_num_rows($result)) { + $items = node_title_list($result); + } + cache_set($cache_id, serialize($items), time() + (60 * 60 * 24)); } + $content = theme('node_list', $items, $title); break; } @@ -376,6 +405,7 @@ function forum_update($node) { else { db_query('UPDATE {forum} SET tid = %d WHERE vid = %d', $node->tid, $node->vid); } + cache_clear_all('block:forum:', TRUE); } /** @@ -413,6 +443,7 @@ function forum_prepare(&$node) { */ function forum_insert($node) { db_query('INSERT INTO {forum} (nid, vid, tid) VALUES (%d, %d, %d)', $node->nid, $node->vid, $node->tid); + cache_clear_all('block:forum:', TRUE); } /** @@ -420,6 +451,7 @@ function forum_insert($node) { */ function forum_delete(&$node) { db_query('DELETE FROM {forum} WHERE nid = %d', $node->nid); + cache_clear_all('block:forum:', TRUE); } /** Index: modules/node.module =================================================================== RCS file: /cvs/drupal/drupal/modules/node.module,v retrieving revision 1.654 diff -u -p -r1.654 node.module --- modules/node.module 5 Jul 2006 11:45:51 -0000 1.654 +++ modules/node.module 7 Jul 2006 14:33:33 -0000 @@ -64,18 +64,18 @@ function node_cron() { * * @param $result * A DB result object from a query to fetch node objects. If your query joins the node_comment_statistics table so that the comment_count field is available, a title attribute will be added to show the number of comments. - * @param $title - * A heading for the resulting list. * * @return - * An HTML list suitable as content for a block. + * An array of HTML suitable as content for a block. */ -function node_title_list($result, $title = NULL) { +function node_title_list($result) { + $items = array(); + while ($node = db_fetch_object($result)) { $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); + return $items; } /** @@ -2475,6 +2475,20 @@ function node_db_rewrite_sql($query, $pr } /** + * Returns if the node_access table is used + */ +function node_access_usage() { + static $status = NULL; + + if (!isset($count)) { + $count = db_result(db_query('SELECT COUNT(*) FROM {node_access}')); + $status = ($count > 1) ? TRUE : FALSE; + } + + return $status; +} + +/** * @} End of "defgroup node_access". */