Index: sections.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/sections/sections.module,v
retrieving revision 1.21.2.27
diff -u -r1.21.2.27 sections.module
--- sections.module	20 Dec 2009 21:23:05 -0000	1.21.2.27
+++ sections.module	8 Jun 2010 20:45:59 -0000
@@ -250,8 +250,8 @@
   else {
     // Caller wants to know in which section she is.
     $rids = array_keys($user->roles);
-    $res = db_query(db_rewrite_sql('SELECT DISTINCT s.* FROM {sections_data} s LEFT JOIN {sections_roles} r ON s.sid = r.sid WHERE s.status = 1 AND (r.rid IN ('. db_placeholders($rids) .') OR r.rid IS NULL) ORDER BY s.weight', 's', 'sid'), $rids);
-    while ($row = db_fetch_object($res)) {
+    $res = _sections_roles($rids);
+    foreach ($res as $sid => $row) {
       if ($row->visibility < 2) {
         $path = drupal_get_path_alias($_GET['q']);
         // Compare with the internal and path alias (if any).
@@ -279,6 +279,19 @@
   return FALSE;
 }
 
+function _sections_roles($rids, $reset = FALSE) {
+  static $sections = array();
+  $key = implode('_', $rids);
+  if (!isset($sections[$key]) || $reset) {
+    $sections[$key] = array();
+    $result = db_query(db_rewrite_sql('SELECT DISTINCT s.* FROM {sections_data} s LEFT JOIN {sections_roles} r ON s.sid = r.sid WHERE s.status = 1 AND (r.rid IN ('. db_placeholders($rids) .') OR r.rid IS NULL) ORDER BY s.weight', 's', 'sid'), $rids);
+    while ($row = db_fetch_object($result)) {
+      $sections[$key][$row->sid] = $row;
+    }
+  }
+  return $sections[$key];
+}
+
 /**
  * Implementation of hook_preprocess().
  */
