summaryrefslogtreecommitdiff
path: root/modules/user/user.module
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2003-11-28 20:03:00 +0000
committerDries Buytaert <dries@buytaert.net>2003-11-28 20:03:00 +0000
commit733d286b8991ffa6c0b13c20255c5806913e869b (patch)
tree40b93497e8c26d4b71599f78e4025197696ddf0b /modules/user/user.module
parentfa5aca1ef79e318793fe9cc13befabe8b01e3b36 (diff)
downloadbrdo-733d286b8991ffa6c0b13c20255c5806913e869b.tar.gz
brdo-733d286b8991ffa6c0b13c20255c5806913e869b.tar.bz2
- Made it possible to auto-throttle blocks. That is, blocks can be
configured to be disabled when under excessive load. Patch by Jeremy.
Diffstat (limited to 'modules/user/user.module')
-rw-r--r--modules/user/user.module69
1 files changed, 28 insertions, 41 deletions
diff --git a/modules/user/user.module b/modules/user/user.module
index 3ef659104..2c40b8632 100644
--- a/modules/user/user.module
+++ b/modules/user/user.module
@@ -383,52 +383,39 @@ function user_block($op = "list", $delta = 0) {
}
case 3:
if (user_access("access content")) {
- /* utilize auto-throttle to disable when this site is too busy */
- if (function_exists("throttle_status"))
- $throttle = throttle_status();
- else
- $throttle = 0;
-
- /* be sure the site isn't too busy prior to performing db queries */
- if ($throttle < 5) {
- /* count users with activity in the past defined period */
- $time_period = variable_get("user_block_seconds_online", 2700);
-
- /* perform database queries to gather online user lists */
- $guests = db_fetch_object(db_query("SELECT COUNT(DISTINCT sid) AS count FROM {sessions} WHERE timestamp >= %d AND uid = 0", time() - $time_period));
- $users = db_query("SELECT DISTINCT uid, MAX(timestamp) AS max_timestamp FROM {sessions} WHERE timestamp >= %d AND uid != 0 GROUP BY uid ORDER BY max_timestamp DESC", time() - $time_period );
- $total_users = db_affected_rows();
-
- /* format the output with proper grammar */
- if ($total_users == 1 && $guests->count == 1) {
- $output = t("There is currently %members and %visitors online.", array("%members" => format_plural($total_users, "1 user", "%count users"), "%visitors" => format_plural($guests->count, "1 guest", "%count guests")));
- }
- else {
- $output = t("There are currently %members and %visitors online.", array("%members" => format_plural($total_users, "1 user", "%count users"), "%visitors" => format_plural($guests->count, "1 guest", "%count guests")));
- }
+ /* count users with activity in the past defined period */
+ $time_period = variable_get("user_block_seconds_online", 2700);
- if (user_access("access user list") && $total_users) {
- /* Display a list of currently online users */
- $max_users = variable_get("user_block_max_list_count", 10);
- $items = array();
- while ($uid = db_fetch_object($users)) {
- $items[] = format_name(user_load(array("uid" => $uid->uid)));
- }
-
- if ($items) {
- $output .= "<br /><br />";
- $output .= theme("item_list", $items, t("Online users:"));
- }
- }
+ /* perform database queries to gather online user lists */
+ $guests = db_fetch_object(db_query("SELECT COUNT(DISTINCT sid) AS count FROM {sessions} WHERE timestamp >= %d AND uid = 0", time() - $time_period));
+ $users = db_query("SELECT DISTINCT uid, MAX(timestamp) AS max_timestamp FROM {sessions} WHERE timestamp >= %d AND uid != 0 GROUP BY uid ORDER BY max_timestamp DESC", time() - $time_period );
+ $total_users = db_affected_rows();
+
+ /* format the output with proper grammar */
+ if ($total_users == 1 && $guests->count == 1) {
+ $output = t("There is currently %members and %visitors online.", array("%members" => format_plural($total_users, "1 user", "%count users"), "%visitors" => format_plural($guests->count, "1 guest", "%count guests")));
}
else {
- /* the site is too busy -- display a simple "too busy" message */
- $output = t("This site is currently sustaining more than %total page views a minute.", array("%total" => ($throttle * variable_get("statistics_throttle_multiplier", 60))));
+ $output = t("There are currently %members and %visitors online.", array("%members" => format_plural($total_users, "1 user", "%count users"), "%visitors" => format_plural($guests->count, "1 guest", "%count guests")));
+ }
+
+ if (user_access("access user list") && $total_users) {
+ /* Display a list of currently online users */
+ $max_users = variable_get("user_block_max_list_count", 10);
+ $items = array();
+ while ($uid = db_fetch_object($users)) {
+ $items[] = format_name(user_load(array("uid" => $uid->uid)));
+ }
+
+ if ($items) {
+ $output .= "<br /><br />";
+ $output .= theme("item_list", $items, t("Online users:"));
+ }
}
- $block["subject"] = t("Who's online");
- $block["content"] = $output;
- return $block;
}
+ $block["subject"] = t("Who's online");
+ $block["content"] = $output;
+ return $block;
}
}
}