Commit 0a4b876a authored by Leigh Stoller's avatar Leigh Stoller

An optimization; Instead of per-user DB queries (now 203) to get

project list for each user, do one big query for all users at the
beginning of the script.
Also some minor format changes.
parent 3c19afd2
......@@ -79,10 +79,37 @@ else {
"order by $order");
}
if (mysql_num_rows($query_result) == 0) {
if (($count = mysql_num_rows($query_result)) == 0) {
USERERROR("There are no users!", 1);
}
if ($showactive) {
echo "<center>
There are $count users logged in.
</center><br>\n";
}
else {
echo "<center>
There are $count users.
</center><br>\n";
}
#
# Grab the project lists and create a hash of lists, per user.
# One query instead of hundreds.
#
$projmemb_result =
DBQueryFatal("select distinct uid,pid from group_membership order by uid");
$projmemb_array = array();
while ($row = mysql_fetch_array($projmemb_result)) {
$uid = $row[0];
$pid = $row[1];
$projmemb_array[$uid][] = $pid;
}
echo "<table width=\"100%\" border=2 cellpadding=1 cellspacing=0
align='center'>\n";
......@@ -116,13 +143,6 @@ while ($row = mysql_fetch_array($query_result)) {
$webidle = $row[webidle];
$usersidle= $row[usersidle];
#
# Suck out a list of projects too.
#
$projmemb_result = mysql_db_query($TBDBNAME,
"SELECT distinct pid FROM group_membership ".
"where uid='$thisuid' order by pid");
echo "<tr>\n";
if (strcmp($status, "active") == 0 ||
......@@ -136,21 +156,21 @@ while ($row = mysql_fetch_array($query_result)) {
echo "<td><A href='showuser.php3?target_uid=$thisuid'>$thisuid</A></td>
<td>$name</td>\n";
if ($count = mysql_num_rows($projmemb_result)) {
echo "<td> ";
while ($projrow = mysql_fetch_array($projmemb_result)) {
$pid = $projrow[pid];
echo "<A href='showproject.php3?pid=$pid'>$pid</A>";
$count--;
if ($count)
echo ", ";
}
echo "</td>\n";
# List of projects.
reset($projmemb_array);
if (isset($projmemb_array[$thisuid])) {
echo "<td> ";
while (list ($idx, $pid) = each($projmemb_array[$thisuid])) {
echo "<A href='showproject.php3?pid=$pid'>$pid</A>";
if ($idx)
echo ", ";
}
echo "</td>\n";
}
else {
echo "<td>--</td>\n";
}
echo "<td>$webidle</td>\n";
if (! $usersidle)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment