Changeset 1260
- Timestamp:
- 07/19/07 16:29:48 (5 years ago)
- Location:
- trunk/wifidog-auth
- Files:
-
- 3 modified
-
CHANGELOG (modified) (1 diff)
-
wifidog/classes/Node.php (modified) (8 diffs)
-
wifidog/include/schema_validate.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wifidog-auth/CHANGELOG
r1259 r1260 1 1 # $Id: $ 2 2 3 2007-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 3 9 2007-07-17 Benoit Grégoire <bock@step.polymtl.ca> 4 10 * Use last_heartbeat_sys_uptime untill #354 is fixed -
trunk/wifidog-auth/wifidog/classes/Node.php
r1253 r1260 149 149 if(!isset($currentRealNodeComputed)) 150 150 { 151 //echo "getCurrentTealNode(): Computing for IP $currentIp<br/>"; 151 152 $currentRealNodeComputed=true; 152 153 $db = AbstractDb::getObject(); … … 813 814 return $this->_row['last_heartbeat_wifidog_uptime']; 814 815 } 815 816 816 817 function getLastHeartbeatSysUptime() 817 818 { 818 819 return $this->_row['last_heartbeat_sys_uptime']; 819 820 } 820 821 821 822 function getLastHeartbeatSysLoad() 822 823 { 823 824 return $this->_row['last_heartbeat_sys_load']; 824 825 } 825 826 826 827 function getLastHeartbeatSysMemfree() 827 828 { 828 829 return $this->_row['last_heartbeat_sys_memfree']; 829 830 } 830 831 831 832 function getLastHeartbeatTimestamp() 832 833 { … … 1314 1315 1315 1316 /** 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. 1317 1319 * 1318 1320 * @return array An array of User object, or an empty array … … 1322 1324 public function getRecentUsers() 1323 1325 { 1324 1326 $numUsers = 5; 1325 1327 $db = AbstractDb::getObject(); 1326 1328 … … 1331 1333 $weekAgoDate = strftime("%Y-%m-%d 00:00", strtotime("-1 week")); 1332 1334 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); 1334 1387 1335 1388 if ($users != null) { … … 1342 1395 } 1343 1396 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 } 1344 1400 /** 1345 * The list of the 5 users who have logged into this node most often1401 * The list of users online at this node 1346 1402 * 1347 1403 * @return array An array of User object, or an empty array … … 1349 1405 * @access public 1350 1406 */ 1351 public function get ActiveUsers()1407 public function getOnlineUsers() 1352 1408 { 1353 1409 … … 1358 1414 $users = null; 1359 1415 $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); 1391 1417 if ($users != null) { 1392 1418 foreach ($users as $user_row) { -
trunk/wifidog-auth/wifidog/include/schema_validate.php
r1257 r1260 48 48 * Define current database schema version 49 49 */ 50 define('REQUIRED_SCHEMA_VERSION', 5 5);50 define('REQUIRED_SCHEMA_VERSION', 56); 51 51 /** Used to test a new shecma version before modyfying the database */ 52 52 define('SCHEMA_UPDATE_TEST_MODE', false); … … 1283 1283 $sql .= "ALTER TABLE nodes ALTER COLUMN last_heartbeat_sys_load SET DEFAULT NULL;\n"; 1284 1284 } 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 1285 1293 /* 1286 1294 $new_schema_version = ;
