Message info
 
To:aur-dev@archlinux.org From:Lukas Fleischer Subject:Re: [aur-dev] [PATCH] user_table optimization Date:Sun, 6 May 2012 12:56:21 +0200
 

On Wed, May 02, 2012 at 04:14:01PM -0500, Dan McGee wrote:
> Rather than looking up by username, it makes more sense to look the
> stats up by user ID to reduce the number of needed joins.
>
> Signed-off-by: Dan McGee <dan@archlinux.org>
> ---
> web/html/index.php | 4 ++--
> web/lib/stats.inc.php | 11 +++++------
> 2 files changed, 7 insertions(+), 8 deletions(-)
>

Applied to master. Thanks!

> diff --git a/web/html/index.php b/web/html/index.php
> index 0d513d3..21de99d 100644
> --- a/web/html/index.php
> +++ b/web/html/index.php
> @@ -58,8 +58,8 @@ echo __(
> <td class='boxSoft' valign='top'>
> <?php
> if (!empty($_COOKIE["AURSID"])) {
> - $user = username_from_sid($_COOKIE["AURSID"]);
> - user_table($user, $dbh);
> + $userid = uid_from_sid($_COOKIE["AURSID"]);
> + user_table($userid, $dbh);
> echo '<br />';
> }
>
> diff --git a/web/lib/stats.inc.php b/web/lib/stats.inc.php
> index 8f0f770..6659f6d 100644
> --- a/web/lib/stats.inc.php
> +++ b/web/lib/stats.inc.php
> @@ -18,18 +18,17 @@ function updates_table($dbh)
> include('stats/updates_table.php');
> }
>
> -function user_table($user, $dbh)
> +function user_table($userid, $dbh)
> {
> - $escuser = db_escape_string($user);
> - $base_q = "SELECT count(*) FROM Packages,Users WHERE Packages.MaintainerUID = Users.ID AND Users.Username='" . $escuser . "'";
> + $base_q = "SELECT count(*) FROM Packages WHERE Packages.MaintainerUID = " . $userid;
>
> $maintainer_unsupported_count = db_cache_value($base_q, $dbh,
> - 'user_unsupported_count:' . $escuser);
> + 'user_unsupported_count:' . $userid);
>
> - $q = "SELECT count(*) FROM Packages,Users WHERE Packages.OutOfDateTS IS NOT NULL AND Packages.MaintainerUID = Users.ID AND Users.Username='" . $escuser . "'";
> + $q = "SELECT count(*) FROM Packages WHERE Packages.OutOfDateTS IS NOT NULL AND Packages.MaintainerUID = " . $userid;
>
> $flagged_outdated = db_cache_value($q, $dbh,
> - 'user_flagged_outdated:' . $escuser);
> + 'user_flagged_outdated:' . $userid);
>
> # If the user is a TU calculate the number of the packages
> $atype = account_from_sid($_COOKIE["AURSID"]);
> --
> 1.7.10.1