From 6a8e394301c557188e8cd1643b4556eb80dca7b9 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Thu, 14 Oct 2004 21:45:37 +0000 Subject: - Fixed bug #11312: menu caching to aggresively. I did not apply the proposed patch but moved the menu-logic to the $may_cache clause and added some checks to avoid SQL overhead. I think this is the most performant solution. --- modules/book.module | 14 +++++++++----- modules/book/book.module | 14 +++++++++----- 2 files changed, 18 insertions(+), 10 deletions(-) (limited to 'modules') diff --git a/modules/book.module b/modules/book.module index 02323e2b1..d3348096e 100644 --- a/modules/book.module +++ b/modules/book.module @@ -90,11 +90,6 @@ function book_menu($may_cache) { 'callback' => 'book_admin_orphan', 'access' => user_access('administer nodes'), 'weight' => 8); - $result = db_query('SELECT n.nid, n.title FROM {node} n '. node_access_join_sql() .' INNER JOIN {book} b ON n.nid = b.nid WHERE '. node_access_where_sql() .' AND b.parent = 0 ORDER BY b.weight, n.title'); - while ($book = db_fetch_object($result)) { - $items[] = array('path' => 'admin/node/book/'. $book->nid, 'title' => t('"%title" book', array('%title' => $book->title))); - } - $items[] = array('path' => 'book', 'title' => t('books'), 'callback' => 'book_render', 'access' => user_access('access content'), @@ -116,6 +111,15 @@ function book_menu($may_cache) { 'type' => MENU_LOCAL_TASK, 'weight' => 2); } } + + // We don't want to cache these menu items because they could change whenever + // a book page or outline node is edited. + if (arg(0) == 'admin' && arg(1) == 'node' && arg(2) == 'book') { + $result = db_query('SELECT n.nid, n.title FROM {node} n '. node_access_join_sql() .' INNER JOIN {book} b ON n.nid = b.nid WHERE '. node_access_where_sql() .' AND b.parent = 0 ORDER BY b.weight, n.title'); + while ($book = db_fetch_object($result)) { + $items[] = array('path' => 'admin/node/book/'. $book->nid, 'title' => t('"%title" book', array('%title' => $book->title))); + } + } } return $items; diff --git a/modules/book/book.module b/modules/book/book.module index 02323e2b1..d3348096e 100644 --- a/modules/book/book.module +++ b/modules/book/book.module @@ -90,11 +90,6 @@ function book_menu($may_cache) { 'callback' => 'book_admin_orphan', 'access' => user_access('administer nodes'), 'weight' => 8); - $result = db_query('SELECT n.nid, n.title FROM {node} n '. node_access_join_sql() .' INNER JOIN {book} b ON n.nid = b.nid WHERE '. node_access_where_sql() .' AND b.parent = 0 ORDER BY b.weight, n.title'); - while ($book = db_fetch_object($result)) { - $items[] = array('path' => 'admin/node/book/'. $book->nid, 'title' => t('"%title" book', array('%title' => $book->title))); - } - $items[] = array('path' => 'book', 'title' => t('books'), 'callback' => 'book_render', 'access' => user_access('access content'), @@ -116,6 +111,15 @@ function book_menu($may_cache) { 'type' => MENU_LOCAL_TASK, 'weight' => 2); } } + + // We don't want to cache these menu items because they could change whenever + // a book page or outline node is edited. + if (arg(0) == 'admin' && arg(1) == 'node' && arg(2) == 'book') { + $result = db_query('SELECT n.nid, n.title FROM {node} n '. node_access_join_sql() .' INNER JOIN {book} b ON n.nid = b.nid WHERE '. node_access_where_sql() .' AND b.parent = 0 ORDER BY b.weight, n.title'); + while ($book = db_fetch_object($result)) { + $items[] = array('path' => 'admin/node/book/'. $book->nid, 'title' => t('"%title" book', array('%title' => $book->title))); + } + } } return $items; -- cgit v1.2.3