[aur-dev] [PATCH 6/6] Remove db_connect() calls out of index.php front page view

Dan McGee dan at archlinux.org
Mon Aug 22 20:18:56 EDT 2011


This ensures we are passing around a single database handle the whole
time, and reusing data if we already have it in request scope.

Signed-off-by: Dan McGee <dan at archlinux.org>
---

Not as big of difference as the package details one, but pretty low-handing
fruit.

 web/html/index.php                |   13 +++++--------
 web/lib/stats.inc.php             |    8 ++++----
 web/template/stats/user_table.php |    4 ----
 3 files changed, 9 insertions(+), 16 deletions(-)

diff --git a/web/html/index.php b/web/html/index.php
index 0d513d3..e7b7139 100644
--- a/web/html/index.php
+++ b/web/html/index.php
@@ -3,17 +3,14 @@
 set_include_path(get_include_path() . PATH_SEPARATOR . '../lib');
 
 include_once("aur.inc.php");
-set_lang();
-check_sid();
-
 include_once('stats.inc.php');
+$dbh = db_connect();
+set_lang($dbh);
+check_sid($dbh);
 
-html_header( __("Home") );
+html_header(__("Home"), $dbh);
 
 include('pkg_search_form.php');
-
-$dbh = db_connect();
-
 ?>
 
 <div class="pgbox">
@@ -58,7 +55,7 @@ echo __(
 <td class='boxSoft' valign='top'>
 <?php
 if (!empty($_COOKIE["AURSID"])) {
-	$user = username_from_sid($_COOKIE["AURSID"]);
+	$user = username_from_sid($_COOKIE["AURSID"], $dbh);
 	user_table($user, $dbh);
 	echo '<br />';
 }
diff --git a/web/lib/stats.inc.php b/web/lib/stats.inc.php
index 2690a5c..a8e4605 100644
--- a/web/lib/stats.inc.php
+++ b/web/lib/stats.inc.php
@@ -6,7 +6,7 @@ function updates_table($dbh)
 {
 	$key = 'recent_updates';
 	if(!($newest_packages = get_cache_value($key))) {
-		$q = 'SELECT * FROM Packages ORDER BY ModifiedTS DESC LIMIT 10';
+		$q = 'SELECT ID, Name, Version, ModifiedTS, SubmittedTS FROM Packages ORDER BY ModifiedTS DESC LIMIT 10';
 		$result = db_query($q, $dbh);
 
 		$newest_packages = new ArrayObject();
@@ -18,9 +18,9 @@ function updates_table($dbh)
 	include('stats/updates_table.php');
 }
 
-function user_table($user, $dbh)
+function user_table($username, $dbh)
 {
-	$escuser = mysql_real_escape_string($user);
+	$escuser = mysql_real_escape_string($username);
 	$base_q = "SELECT count(*) FROM Packages,Users WHERE Packages.MaintainerUID = Users.ID AND Users.Username='" . $escuser . "'";
 
 	$maintainer_unsupported_count = db_cache_value($base_q, $dbh,
@@ -32,7 +32,7 @@ function user_table($user, $dbh)
 		'user_flagged_outdated:' . $escuser);
 
 	# If the user is a TU calculate the number of the packages
-	$atype = account_from_sid($_COOKIE["AURSID"]);
+	$atype = account_from_sid($_COOKIE["AURSID"], $dbh);
 
 	include('stats/user_table.php');
 }
diff --git a/web/template/stats/user_table.php b/web/template/stats/user_table.php
index 36a6b10..6e8aa0f 100644
--- a/web/template/stats/user_table.php
+++ b/web/template/stats/user_table.php
@@ -1,6 +1,3 @@
-<?php
- $username = username_from_sid($_COOKIE["AURSID"]); 
-?>
 <table class='boxSoft'>
 <tr>
 <th colspan='2' class='boxSoftTitle'>
@@ -28,4 +25,3 @@
 </td>
 </tr>
 </table>
-
-- 
1.7.6



More information about the aur-dev mailing list