original_string: public static function fill_subscription_cache($forumid, $userid = null) {
          global $DB;
  
          if (!isset(self::$fetchedforums[$forumid])) {
              // This forum has not been fetched as a whole.
              if (isset($userid)) {
                  if (!isset(self::$forumcache[$userid])) {
                      self::$forumcache[$userid] = array();
                  }
  
                  if (!isset(self::$forumcache[$userid][$forumid])) {
                      if ($DB->record_exists('forum_subscriptions', array(
                          'userid' => $userid,
                          'forum' => $forumid,
                      ))) {
                          self::$forumcache[$userid][$forumid] = true;
                      } else {
                          self::$forumcache[$userid][$forumid] = false;
                      }
                  }
              } else {
                  $subscriptions = $DB->get_recordset('forum_subscriptions', array(
                      'forum' => $forumid,
                  ), '', 'id, userid');
                  foreach ($subscriptions as $id => $data) {
                      if (!isset(self::$forumcache[$data->userid])) {
                          self::$forumcache[$data->userid] = array();
                      }
                      self::$forumcache[$data->userid][$forumid] = true;
                  }
                  self::$fetchedforums[$forumid] = true;
                  $subscriptions->close();
              }
          }
      }
code: public static function fill_subscription_cache($forumid, $userid = null) {
          global $DB;
  
          if (!isset(self::$fetchedforums[$forumid])) {
              // This forum has not been fetched as a whole.
              if (isset($userid)) {
                  if (!isset(self::$forumcache[$userid])) {
                      self::$forumcache[$userid] = array();
                  }
  
                  if (!isset(self::$forumcache[$userid][$forumid])) {
                      if ($DB->record_exists('forum_subscriptions', array(
                          'userid' => $userid,
                          'forum' => $forumid,
                      ))) {
                          self::$forumcache[$userid][$forumid] = true;
                      } else {
                          self::$forumcache[$userid][$forumid] = false;
                      }
                  }
              } else {
                  $subscriptions = $DB->get_recordset('forum_subscriptions', array(
                      'forum' => $forumid,
                  ), '', 'id, userid');
                  foreach ($subscriptions as $id => $data) {
                      if (!isset(self::$forumcache[$data->userid])) {
                          self::$forumcache[$data->userid] = array();
                      }
                      self::$forumcache[$data->userid][$forumid] = true;
                  }
                  self::$fetchedforums[$forumid] = true;
                  $subscriptions->close();
              }
          }
      }
code_tokens: public static function fill_subscription_cache ( $ forumid , $ userid = null ) { global $ DB ; if ( ! isset ( self :: $ fetchedforums [ $ forumid ] ) ) { // This forum has not been fetched as a whole. if ( isset ( $ userid ) ) { if ( ! isset ( self :: $ forumcache [ $ userid ] ) ) { self :: $ forumcache [ $ userid ] = array ( ) ; } if ( ! isset ( self :: $ forumcache [ $ userid ] [ $ forumid ] ) ) { if ( $ DB -> record_exists ( 'forum_subscriptions' , array ( 'userid' => $ userid , 'forum' => $ forumid , ) ) ) { self :: $ forumcache [ $ userid ] [ $ forumid ] = true ; } else { self :: $ forumcache [ $ userid ] [ $ forumid ] = false ; } } } else { $ subscriptions = $ DB -> get_recordset ( 'forum_subscriptions' , array ( 'forum' => $ forumid , ) , '' , 'id, userid' ) ; foreach ( $ subscriptions as $ id => $ data ) { if ( ! isset ( self :: $ forumcache [ $ data -> userid ] ) ) { self :: $ forumcache [ $ data -> userid ] = array ( ) ; } self :: $ forumcache [ $ data -> userid ] [ $ forumid ] = true ; } self :: $ fetchedforums [ $ forumid ] = true ; $ subscriptions -> close ( ) ; } } }
docstring: Fill the forum subscription data for the specified userid and forum.
  
  If the userid is not specified, then all subscription data for that forum is fetched in a single query and used
  for subsequent lookups without requiring further database queries.
  
  @param int $forumid The forum to retrieve a cache for
  @param int $userid The user ID
  @return void
docstring_tokens: Fill the forum subscription data for the specified userid and forum .