Changeset 1260

Show
Ignore:
Timestamp:
07/19/07 16:29:48 (5 years ago)
Author:
benoitg
Message:

UIUserList fixes:

  • Node::getRecentUsers(): Get the 5 most recent users, not some random users in the last week. Also, exclude users currently logged-in.
  • Node::getActiveUsers(): Function was unbearably slow, now limit the search space to the last 3 months. Get the 5 user who connected on the most differents days, instead of users with the worst wireless card ;)
  • schema_validate.php: Add index for timestamp_in on connection table.
Location:
trunk/wifidog-auth
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/wifidog-auth/CHANGELOG

    r1259 r1260  
    11# $Id: $ 
    22 
     32007-07-19 Benoit Grégoire  <bock@step.polymtl.ca> 
     4        UIUserList fixes: 
     5        * Node::getRecentUsers():  Get the 5 most recent users, not some random users in the last week.  Also, exclude users currently logged-in. 
     6        * Node::getActiveUsers():  Function was unbearably slow, now limit the search space to the last 3 months.  Get the 5 user who connected on the most differents days, instead of users with the worst wireless card ;)  
     7        * schema_validate.php: Add index for timestamp_in on connection table. 
     8         
    392007-07-17 Benoit Grégoire  <bock@step.polymtl.ca> 
    410        * Use last_heartbeat_sys_uptime untill #354 is fixed 
  • trunk/wifidog-auth/wifidog/classes/Node.php

    r1253 r1260  
    149149        if(!isset($currentRealNodeComputed)) 
    150150        { 
     151            //echo "getCurrentTealNode(): Computing for IP $currentIp<br/>"; 
    151152            $currentRealNodeComputed=true; 
    152153            $db = AbstractDb::getObject(); 
     
    813814        return $this->_row['last_heartbeat_wifidog_uptime']; 
    814815    } 
    815      
     816 
    816817    function getLastHeartbeatSysUptime() 
    817818    { 
    818819        return $this->_row['last_heartbeat_sys_uptime']; 
    819820    } 
    820      
     821 
    821822    function getLastHeartbeatSysLoad() 
    822823    { 
    823824        return $this->_row['last_heartbeat_sys_load']; 
    824825    } 
    825      
     826 
    826827    function getLastHeartbeatSysMemfree() 
    827828    { 
    828829        return $this->_row['last_heartbeat_sys_memfree']; 
    829830    } 
    830        
     831 
    831832    function getLastHeartbeatTimestamp() 
    832833    { 
     
    13141315 
    13151316    /** 
    1316      * The list of the 5 most recent users who have logged into this node in the past week 
     1317     * The list of the 5 most recent users who have logged into this node in the past week, 
     1318     * excluding those that are currently connected. 
    13171319     * 
    13181320     * @return array An array of User object, or an empty array 
     
    13221324    public function getRecentUsers() 
    13231325    { 
    1324           
     1326        $numUsers = 5; 
    13251327        $db = AbstractDb::getObject(); 
    13261328 
     
    13311333        $weekAgoDate = strftime("%Y-%m-%d 00:00", strtotime("-1 week")); 
    13321334 
    1333         $db->execSql("SELECT DISTINCT users.user_id FROM users,connections WHERE connections.timestamp_in>'{$weekAgoDate}' AND users.user_id=connections.user_id AND connections.node_id='{$this->id}' LIMIT 5", $users, false); 
     1335        $sql = null; 
     1336        $sql .= "SELECT user_id, timestamp_in FROM connections \n"; 
     1337        $sql .= "WHERE connections.node_id='{$this->id}' \n"; 
     1338        $sql .= "AND connections.user_id NOT IN (".$this->getOnlineUsersSql().")  \n"; 
     1339        $sql .= "AND connections.timestamp_in>'{$weekAgoDate}' \n"; 
     1340 
     1341        $sql .= "ORDER BY connections.timestamp_in DESC\n"; 
     1342        $sql .= "LIMIT $numUsers * 4 \n"; 
     1343        $db->execSql($sql, $users, false); 
     1344 
     1345        if ($users != null) { 
     1346            $alreadyPresentArray[] = array(); //Only keep the top $num 
     1347            $count = 0; 
     1348            foreach ($users as $user_row) { 
     1349                if(empty($alreadyPresentArray[$user_row['user_id']])) { 
     1350                    $retval[] = User::getObject($user_row['user_id']); 
     1351                    $alreadyPresentArray[$user_row['user_id']]=true; 
     1352                    $count++; 
     1353                    if($count>=$numUsers) { 
     1354                        break; 
     1355                    } 
     1356                } 
     1357            } 
     1358        } 
     1359 
     1360        return $retval; 
     1361    } 
     1362 
     1363    /** 
     1364     * The list of the 5 users who have logged into this node the most different days during the last 3 months 
     1365     * 
     1366     * @return array An array of User object, or an empty array 
     1367     * 
     1368     * @access public 
     1369     */ 
     1370    public function getActiveUsers() 
     1371    { 
     1372        $numUsers = 5; 
     1373        $db = AbstractDb::getObject(); 
     1374 
     1375        // Init values 
     1376        $retval = array(); 
     1377        $users = null; 
     1378        $anonUsers = 0; 
     1379        $sql = null; 
     1380        $sql .= "SELECT DISTINCT connections.user_id, count(distinct date_trunc('day', timestamp_in)) as connections FROM connections \n"; 
     1381        $sql .= " WHERE connections.node_id='{$this->id}' \n"; 
     1382        $sql .= " AND timestamp_in > (CURRENT_TIMESTAMP - interval '3 month') \n"; 
     1383        $sql .= " GROUP BY connections.user_id  \n"; 
     1384        $sql .= "ORDER BY connections desc \n"; 
     1385        $sql .= " LIMIT $numUsers\n"; 
     1386        $db->execSql($sql, $users, false); 
    13341387 
    13351388        if ($users != null) { 
     
    13421395    } 
    13431396 
     1397    private function getOnlineUsersSql() { 
     1398        return "SELECT users.user_id FROM users,connections WHERE connections.token_status='".TOKEN_INUSE."' AND users.user_id=connections.user_id AND connections.node_id='{$this->id}'"; 
     1399    } 
    13441400    /** 
    1345      * The list of the 5 users who have logged into this node most often 
     1401     * The list of users online at this node 
    13461402     * 
    13471403     * @return array An array of User object, or an empty array 
     
    13491405     * @access public 
    13501406     */ 
    1351     public function getActiveUsers() 
     1407    public function getOnlineUsers() 
    13521408    { 
    13531409          
     
    13581414        $users = null; 
    13591415        $anonUsers = 0; 
    1360  
    1361         $db->execSql("SELECT DISTINCT users.user_id, count(users.user_id) as connections FROM users, connections WHERE users.user_id=connections.user_id AND connections.node_id='{$this->id}' GROUP BY users.user_id ORDER BY connections desc LIMIT 5", $users, false); 
    1362  
    1363         if ($users != null) { 
    1364             foreach ($users as $user_row) { 
    1365                 $retval[] = User::getObject($user_row['user_id']); 
    1366             } 
    1367         } 
    1368  
    1369         return $retval; 
    1370     } 
    1371  
    1372     /** 
    1373      * The list of users online at this node 
    1374      * 
    1375      * @return array An array of User object, or an empty array 
    1376      * 
    1377      * @access public 
    1378      */ 
    1379     public function getOnlineUsers() 
    1380     { 
    1381           
    1382         $db = AbstractDb::getObject(); 
    1383  
    1384         // Init values 
    1385         $retval = array(); 
    1386         $users = null; 
    1387         $anonUsers = 0; 
    1388  
    1389         $db->execSql("SELECT users.user_id FROM users,connections WHERE connections.token_status='".TOKEN_INUSE."' AND users.user_id=connections.user_id AND connections.node_id='{$this->id}'", $users, false); 
    1390  
     1416        $db->execSql($this->getOnlineUsersSql(), $users, false); 
    13911417        if ($users != null) { 
    13921418            foreach ($users as $user_row) { 
  • trunk/wifidog-auth/wifidog/include/schema_validate.php

    r1257 r1260  
    4848 * Define current database schema version 
    4949 */ 
    50 define('REQUIRED_SCHEMA_VERSION', 55); 
     50define('REQUIRED_SCHEMA_VERSION', 56); 
    5151/** Used to test a new shecma version before modyfying the database */ 
    5252define('SCHEMA_UPDATE_TEST_MODE', false); 
     
    12831283        $sql .= "ALTER TABLE nodes ALTER COLUMN last_heartbeat_sys_load SET DEFAULT NULL;\n"; 
    12841284     } 
     1285      
     1286     $new_schema_version = 56; 
     1287     if ($schema_version < $new_schema_version && $new_schema_version <= $targetSchema) { 
     1288     printUpdateVersion($new_schema_version); 
     1289     $sql .= "\n\nUPDATE schema_info SET value='$new_schema_version' WHERE tag='schema_version';\n"; 
     1290        $sql .= "CREATE INDEX idx_connections_timestamp_in ON connections (timestamp_in);\n"; 
     1291     } 
     1292      
    12851293    /* 
    12861294     $new_schema_version = ;