--- menu_per_role.module.orig 2010-06-18 13:46:13.000000000 -0400 +++ menu_per_role.module 2010-06-18 13:55:02.000000000 -0400 @@ -191,13 +191,30 @@ function menu_per_role_translated_menu_l * No roles mean that access is granted by this module. */ function _menu_per_role_get_roles($mlid) { - $result = db_query("SELECT rids FROM {menu_per_role} WHERE mlid = %d", $mlid); - if ($result && ($row = db_fetch_object($result)) && $row->rids) { - return explode(',', $row->rids); + static $mlid_rids_retrieved = 0; + static $mlid_rids = NULL; + + if (($mlid_rids == NULL) && (!$mlid_rids_retrieved)) { + $result = db_query("SELECT mlid, rids FROM {menu_per_role}"); + if ($result) { + while ($row = db_fetch_object($result)) { + if ($row->rids) { + $mlid_rids[$row->mlid] = explode(',', $row->rids); + } + } + } + $mlid_rids_retrieved = 1; + if ($mlid_rids == NULL) { // if there are no restrictions... + $mlid_rids = array(); + } + } + + if (array_key_exists($mlid, $mlid_rids)) { + return $mlid_rids[$mlid]; + } + else { + return array(); } - - // not defined, everyone has the right to use it - return array(); } /* @@ -205,13 +222,30 @@ function _menu_per_role_get_roles($mlid) * No roles mean that access is granted by this module. */ function _menu_per_role_get_hide_from_roles($mlid) { - $result = db_query("SELECT hrids FROM {menu_per_role} WHERE mlid = %d", $mlid); - if ($result && ($row = db_fetch_object($result)) && $row->hrids) { - return explode(',', $row->hrids); + static $mlid_hrids_retrieved = 0; + static $mlid_hrids = NULL; + + if (($mlid_hrids == NULL) && (!$mlid_hrids_retrieved)) { + $result = db_query("SELECT mlid, hrids FROM {menu_per_role}"); + if ($result) { + while ($row = db_fetch_object($result)) { + if ($row->hrids) { + $mlid_hrids[$row->mlid] = explode(',', $row->hrids); + } + } + } + $mlid_hrids_retrieved = 1; + if ($mlid_hrids == NULL) { // if there are no exclusions... + $mlid_hrids = array(); + } + } + + if (array_key_exists($mlid, $mlid_hrids)) { + return $mlid_hrids[$mlid]; + } + else { + return array(); } - - // not defined, everyone has the right to use it - return array(); } // vim: ts=2 sw=2 et syntax=php