From 6929b259b8ec11031d67b9cbe9f4dc8833700f19 Mon Sep 17 00:00:00 2001 From: Anthony Parsons Date: Tue, 8 Nov 2005 20:37:48 +0000 Subject: [PATCH] HTML optimised: usernames are only linked first time they're shown on the page. --- index.php | 24 +++++++++++++----------- lib/class.anonuser.php | 22 +++++++++++++++------- lib/class.authuser.php | 20 ++++++++++++++++---- 3 files changed, 44 insertions(+), 22 deletions(-) diff --git a/index.php b/index.php index e0bcd0a..e38768a 100644 --- a/index.php +++ b/index.php @@ -19,12 +19,18 @@ switch ( $user->boardlist_layout ) { $list = $DB->query('SELECT `userid`, `alias` FROM `users` WHERE `last_active_date` > UNIX_TIMESTAMP() - 600 - ORDER BY `alias` ASC'); -$count = $list->num_rows; + ORDER BY `last_active_date` ASC LIMIT 30'); + +if ( 30 == $list->num_rows ) + list($count) = $DB->query('SELECT COUNT(*) FROM `users` + WHERE `last_active_date` > UNIX_TIMESTAMP() - 600')->fetch_row(); +else + $count = $list->num_rows; + $onlinestring = ( $count == 1 ? - 'There is %d user online' : - 'There are %d users online' ); + 'There is %d user online: ' : + 'There are %d users online: ' ); ?>

Statistics

@@ -32,14 +38,10 @@ $onlinestring = ( $count == 1 ? \n"; + $GLOBALS['page']->headers |= page::Userheader; } } @@ -57,12 +58,19 @@ class anonuser { if ( empty($this->namecache[$id]) ) { if ( $name === null ) - $this->namecache[$id] = $GLOBALS['DB']->query('SELECT `alias` FROM `users` WHERE `userid` = '.$id) - ->fetch_object()->alias; - else - $this->namecache[$id] = $name; - } - return $this->namecache[$id]; + list($name) = $GLOBALS['DB']->query('SELECT `alias` FROM `users` + WHERE `userid` = '.$id)->fetch_row(); + + return ($this->namecache[$id] = $name); + } else + return $this->namecache[$id]; + } + + function fillnamecache(mysqli_result $rows) + { + while ( list($a, $b) = $rows->fetch_row() ) + $this->namecache[$a] = $c[$a] = $b; + return $c; } function fdate($timestamp) diff --git a/lib/class.authuser.php b/lib/class.authuser.php index 82e2af9..6665cdc 100644 --- a/lib/class.authuser.php +++ b/lib/class.authuser.php @@ -117,12 +117,24 @@ class authuser extends reguser { if ( empty($this->namecache[$id]) ) { if ( $name === null ) - list($this->namecache[$id]) = $GLOBALS['DB']->query('SELECT `alias` FROM `users` - WHERE `userid` = '.$id)->fetch_row(); + list($name) = $GLOBALS['DB']->query('SELECT `alias` FROM `users` + WHERE `userid` = '.$id)->fetch_row(); + + $this->namecache[$id] = $name; + return sprintf('%2$s', $id, $name); + } else + return $this->namecache[$id]; + } + + function fillnamecache(mysqli_result $rows) + { + while ( list($a, $b) = $rows->fetch_row() ) { + if ( empty($this->namecache[$a]) ) + ($this->namecache[$a] = $b) && $c[$a] = sprintf('%2$s', $a, $b); else - $this->namecache[$id] = $name; + $c[$a] = $this->namecache[$a]; } - return ''.$this->namecache[$id].''; + return $c; } // timrod sucks cats -- 2.11.4.GIT