Update of /cvsroot/fink/web/pdb
In directory sc8-pr-cvs17:/tmp/cvs-serv17407
Modified Files:
browse.php compare.php index.php package.php sections.php
Added Files:
memcache.inc
Log Message:
change to do sql query caching
Index: index.php
===================================================================
RCS file: /cvsroot/fink/web/pdb/index.php,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- index.php 27 Sep 2007 19:51:09 -0000 1.25
+++ index.php 27 Sep 2007 23:03:14 -0000 1.26
@@ -4,6 +4,7 @@
$cvs_date = '$Date$';
include "header.inc";
+include "memcache.inc";
?>
<h1>Package Database Introduction</h1>
@@ -34,31 +35,31 @@
<?
$q = "SELECT COUNT(DISTINCT name) FROM package";
-$rs = mysql_query($q, $dbh);
+$rs = cachedQuery($q);
if (!$rs) {
print '<p><b>error during query:</b> '.mysql_error().'</p>';
$pkgcount = '?';
} else {
- $pkgcount = mysql_fetch_array($rs);
+ $pkgcount = array_shift($rs);
$pkgcount = $pkgcount[0];
}
$q = "SELECT MAX(UNIX_TIMESTAMP(infofilechanged)) FROM package";
-$rs = mysql_query($q, $dbh);
+$rs = cachedQuery($q);
if (!$rs) {
print '<p><b>error during query:</b> '.mysql_error().'</p>';
$dyndate = '';
} else {
- $dyndate = mysql_fetch_array($rs);
+ $dyndate = array_shift($rs);
$dyndate = $dyndate[0];
}
$q = "SELECT * FROM sections ORDER BY name ASC";
-$rs = mysql_query($q, $dbh);
+$rs = cachedQuery($q);
if (!$rs) {
print '<p><b>error during query:</b> '.mysql_error().'</p>';
} else {
- $seccount = mysql_num_rows($rs);
+ $seccount = count($rs);
?>
<p>
@@ -80,10 +81,8 @@
<ul>
<?
- while ($row = mysql_fetch_array($rs)) {
- print '<li><a href="browse.php?section='.$row[name].'">'.$row[name].'</a>'.
- ($row[description] ? (' - '.$row[description]) : '').
- '</li>'."\n";
+ foreach ($rs as $row) {
+ print '<li><a
href="browse.php?section='.$row[name].'">'.$row[name].'</a>'.
($row[description] ? (' - '.$row[description]) : ''). '</li>'."\n";
}
?>
</ul>
Index: compare.php
===================================================================
RCS file: /cvsroot/fink/web/pdb/compare.php,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- compare.php 21 Jun 2007 16:20:04 -0000 1.19
+++ compare.php 27 Sep 2007 23:03:14 -0000 1.20
@@ -5,6 +5,7 @@
include "header.inc";
include "releases.inc";
+include "memcache.inc";
?>
<STYLE TYPE="text/css">
.bgreen { background: #66FF10; display: inline; }
@@ -63,7 +64,7 @@
$name = $matches[1];
$q = "UPDATE move SET moveflag = ".($op - 1)." WHERE
(`release` = '".$tree1.
"' AND name='".$name."')";
- $rsr = mysql_query($q, $dbh);
+ $rsr = cached_query($q);
if (mysql_errno()) {
print '<p><b>errno $err error during
UPDATE:</b> '.mysql_error().'</p>';
die;
@@ -72,11 +73,11 @@
}
}
$q = "SELECT * FROM `release`";
-$rs = mysql_query($q, $dbh);
+$rs = cached_query($q);
if (!$rs) {
print "<p><b>error during query ".$q.':</b> '.mysql_error().'</p>';
} else {
- while ($row = mysql_fetch_array($rs)) {
+ foreach ($rs as $row) {
$menu = $menu . '<option value="'. $row['name']. '" '.
(strcmp($row['name'], $tree1) ? '>' : 'selected>').
$row['name'];
@@ -117,11 +118,11 @@
"WHERE `release` LIKE \"$tree1\" ".
($splitoffs ? '' : 'AND parentname IS NULL ').
"ORDER BY ".(strcmp($sort, "name") ? 'maintainer,name' : 'name')."
ASC";
-$rs = mysql_query($q, $dbh);
-if (!$rs) {
+$rs = cachedQuery($q);
+if (mysql_errno()) {
print "<p><b>error during query ".$q.':</b> '.mysql_error().'</p>';
} else {
- $count = mysql_num_rows($rs);
+ $count = count($rs);
print '<p>'.$count." Packages Found in $tree1</p>";
$hitcount = 0;
@@ -134,14 +135,14 @@
print "\"Wow, you know that's a lot of checkboxes\" - Check packages
then click the buttons below to change a line's status.<br>";
}
$pkglist = $pkglist . "<ul>\n";
- while ($row = mysql_fetch_array($rs)) {
+ foreach ($rs as $row) {
$q2 = "SELECT name FROM package ".
"WHERE `release` LIKE \"$tree2\" AND name=\"" . $row['name'] . '"';
- $rs2 = mysql_query($q2, $dbh);
- if (!$rs2) {
+ $rs2 = cachedQuery($q2);
+ if (mysql_errno()) {
print "<p><b>error during query ".$q2.':</b> '.mysql_error().'</p>';
} else {
- $count = mysql_num_rows($rs2);
+ $count = count($rs2);
$hit = 0;
if($cmp == 0) {
# are NOT - count will be 0
@@ -157,22 +158,22 @@
{
$qmove = "SELECT moveflag FROM move ".
"WHERE `release` LIKE \"$tree1\" AND name=\"" .
$row['name'] . '"';
- $rsm = mysql_query($qmove, $dbh);
+ $rsm = cachedQuery($qmove);
$err = mysql_errno();
- if (!$rsm) {
+ if ($err) {
print '<p><b>errno $err error during
query :</b> '.mysql_error()."$qmove".'</p>';
die;
}
- $mcount = mysql_num_rows($rsm);
+ $mcount = count($rsm);
if($mcount == 0) {
### Must be new here. Insert the record
into the move table
$qmove2 = "INSERT INTO move (`release`,
name, moveflag) VALUES (\"".$tree1.
"\",\"".$row[name]."\", 0)";
- $rs1 = mysql_query($qmove2, $dbh);
+ $rs1 = cachedQuery($qmove2);
$err = mysql_errno();
- if (!$rs1) {
+ if ($err) {
print '<p><b>errno $err error
during query :</b> '.mysql_error()."$qmove2".'</p>';
die;
}
@@ -182,7 +183,7 @@
die("Error: mcount for ".$row[name]."in
move table is $mcount !");
} else {
### Fetch the moveflag from the first
SELECT
- while ($row3 = mysql_fetch_array($rsm))
{
+ foreach ($rsm as $row3) {
$moveflag = $row3[moveflag];
}
}
Index: package.php
===================================================================
RCS file: /cvsroot/fink/web/pdb/package.php,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -d -r1.48 -r1.49
--- package.php 27 Sep 2007 19:51:09 -0000 1.48
+++ package.php 27 Sep 2007 23:03:14 -0000 1.49
@@ -5,6 +5,7 @@
$uses_pathinfo = 1;
include "header.inc";
+include "memcache.inc";
$package = $pispec;
?>
@@ -70,24 +71,22 @@
$qtodisplay_order .= "ORDER BY d.priority DESC,r.priority DESC";
$qtodisplay = $qtodisplay_sel.$qtodisplay_where.$qtodisplay_order;
$error_level = error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING);
-$qs = mysql_query($qtodisplay, $dbh);
+$qs = cachedQuery($qtodisplay);
error_reporting($error_level);
if (!$qs) {
print '<p class="attention"><b>Error during db query (Package):</b>
'.mysql_error().'</p>';
} else {
- $pkg2disp = mysql_fetch_array($qs);
+ $pkg2disp = array_shift($qs);
}
$warning = '';
if (!$pkg2disp) { # No specific version found, try latest
$qtodisplay = $qtodisplay_sel."WHERE p.name='$package' ".$qtodisplay_order;
$error_level = error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING);
- $qs = mysql_query($qtodisplay, $dbh);
+ $qs = cachedQuery($qtodisplay);
error_reporting($error_level);
- if (!$qs) {
- print '<p class="attention"><b>Error during db query (Latest Package):</b>
'.mysql_error().'</p>';
- } else {
- $pkg2disp = mysql_fetch_array($qs);
+ if ($qs) {
+ $pkg2disp = array_shift($qs);
}
$warning = "<b>Warning: Package $package $version not found";
$warning .= $distribution ? " in distribution $distribution" : '';
@@ -190,14 +189,14 @@
if (!$showall)
$q .= "AND visible='1' ";
$q .= "ORDER BY priority DESC";
- $qdist = mysql_query($q, $dbh);
+ $qdist = cachedQuery($q);
if (!$qdist) {
die('<p class="attention"><b>Error during db query (Distributions):</b>
'.mysql_error().'</p>');
}
$color_count = 0;
$last_identifier = '';
$has_unsupported_dists = false;
- while ($dist_row = mysql_fetch_array($qdist)) {
+ foreach ($qdist as $dist_row) {
if ($last_identifier != $dist_row['identifier'])
$color_count++;
if ($color_count == 1) {
@@ -211,13 +210,13 @@
// Query all releases (typically: stable, unstable, bindist) for the given
distribution.
$q = "SELECT r.type FROM `release` r WHERE r.dist_id='" .
$dist_row['dist_id'] . "' AND r.active='1' ORDER BY r.priority ASC";
- $qrel = mysql_query($q, $dbh);
+ $qrel = cachedQuery($q);
if (!$qrel) {
die('<p class="attention"><b>Error during db query (Releases):</b>
'.mysql_error().'</p>');
}
$has_bindist = false;
$has_cvs_rsync = false;
- while ($rel_row = mysql_fetch_array($qrel)) {
+ foreach ($qrel as $rel_row) {
if ($rel_row['type'] == 'bindist')
$has_bindist = true;
elseif ($rel_row['type'] == 'unstable' || $rel_row['type'] == 'stable')
@@ -226,14 +225,11 @@
// Now query all pkginfo per release (typically: stable, unstable, bindist)
for the given distribution.
$q = "SELECT p.*, r.type, r.version AS rel_version FROM `package` p,
`release` r WHERE p.name = '$package' AND p.rel_id = r.rel_id AND r.dist_id='"
. $dist_row['dist_id'] . "' AND active='1' ORDER BY r.priority ASC";
- $qrel = mysql_query($q, $dbh);
- if (!$qrel) {
- die('<p class="attention"><b>Error during db query (Package per
releases):</b> '.mysql_error().'</p>');
- }
+ $qrel = cachedQuery($q);
$pkg_release = array();
- while ($rel_row = mysql_fetch_array($qrel)) {
+ foreach ($qrel as $rel_row) {
$type = $rel_row['type'];
$rel_version = $rel_row["version"]."-".$rel_row["revision"];
if($rel_row["epoch"] > 0)
@@ -358,15 +354,11 @@
// List the splitoffs of this package
$q = "SELECT * FROM `package` WHERE rel_id='$pkg2disp[rel_id]' AND
parentname='$pkg2disp[name]' ORDER BY name";
- $rs = mysql_query($q, $dbh);
- if (!$rs) {
- print '<p class="attention"><b>Error during db query (Splitoffs):</b>
'.mysql_error().'</p>';
- } else {
- if($row = mysql_fetch_array($rs))
- it_item("SplitOffs:", link_to_package($row["name"], $version,
$rel_id, $showall, $row["descshort"]));
- while ($row = mysql_fetch_array($rs)) {
- it_item(" ", link_to_package($row["name"], $version, $rel_id,
$showall, $row["descshort"]));
- }
+ $rs = cachedQuery($q);
+ if($row = array_shift($rs))
+ it_item("SplitOffs:", link_to_package($row["name"], $version,
$rel_id, $showall, $row["descshort"]));
+ foreach ($rs as $row) {
+ it_item(" ", link_to_package($row["name"], $version, $rel_id,
$showall, $row["descshort"]));
}
it_end();
?>
Index: browse.php
===================================================================
RCS file: /cvsroot/fink/web/pdb/browse.php,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- browse.php 27 Sep 2007 19:51:08 -0000 1.6
+++ browse.php 27 Sep 2007 23:03:14 -0000 1.7
@@ -3,7 +3,7 @@
$cvs_author = '$Author$';
$cvs_date = '$Date$';
-
+ini_set("memory_limit", "12M");
function addGETParam(&$params, $param_name) {
$value = stripslashes($_GET[$param_name]);
@@ -47,6 +47,8 @@
$pdb_scripts = true;
include "header.inc";
+include "memcache.inc";
+
?>
<h1>Browse packages</h1>
@@ -113,12 +115,13 @@
if (!$showall)
$q .= "AND visible='1' ";
$q .= "ORDER BY priority DESC";
-$qdist = mysql_query($q, $dbh);
+//$qdist = mysql_query($q, $dbh);
+$qdist = cachedQuery($q);
if (!$qdist) {
die('<p class="attention"><b>Error during db query (distribution):</b>
'.mysql_error().'</p>');
}
$dist_values[''] = 'Any';
-while ($dist = mysql_fetch_array($qdist)) {
+foreach ($qdist as $dist) {
$dist_values[$dist['dist_id']] = $dist['description'];
}
@@ -138,12 +141,13 @@
// Load legal sections
$section_values = array('' => 'Any');
$query = "SELECT * FROM sections ORDER BY name ASC";
-$rs = mysql_query($query, $dbh);
+//$rs = mysql_query($query, $dbh);
+$rs = cachedQuery($query);
if (!$rs) {
print '<p class="attention"><b>Error during db query (sections):</b>
'.mysql_error().'</p>';
} else {
- $seccount = mysql_num_rows($rs);
- while ($row = mysql_fetch_array($rs)) {
+ $seccount = count($rs);
+ foreach ($rs as $row) {
$section_values[$row["name"]] = $row["name"] . " - " .
$row["description"];
}
}
@@ -390,12 +394,14 @@
$query .= "ORDER BY p.name $sort";
$time_sql_start = microtime_float();
-$rs = mysql_query($query, $dbh);
+//$rs = mysql_query($query, $dbh);
+#$rs = cachedQuery($query, MEMCACHE_COMPRESSED);
+$rs = cachedQuery($query);
$time_sql_end = microtime_float();
if (!$rs) {
print '<p class="attention"><b>Error during db query (list packages):</b>
'.mysql_error().'</p>';
} else {
- $count = mysql_num_rows($rs);
+ $count = count($rs);
// Maybe display an overview of the search settings used to obtain the results
here?
@@ -420,7 +426,7 @@
else {
print '<tr class="pdbHeading"><th>Name</th><th>Latest
Version</th><th>Description</th></tr>';
}
- while ($row = mysql_fetch_array($rs)) {
+ foreach ($rs as $row) {
print '<tr class="package">';
if ($tree || $dist)
$rel_id_str = '?rel_id='.$row["rel_id"].($showall ? '&showall=on' : '');
Index: sections.php
===================================================================
RCS file: /cvsroot/fink/web/pdb/sections.php,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- sections.php 27 Sep 2007 19:51:10 -0000 1.7
+++ sections.php 27 Sep 2007 23:03:14 -0000 1.8
@@ -4,6 +4,7 @@
$cvs_date = '$Date$';
include "header.inc";
+include "memcache.inc";
?>
@@ -17,16 +18,16 @@
<?
$q = "SELECT * FROM sections ORDER BY name ASC";
-$rs = mysql_query($q, $dbh);
+$rs = cachedQuery($q);
if (!$rs) {
print '<p><b>error during query:</b> '.mysql_error().'</p>';
} else {
- $seccount = mysql_num_rows($rs);
+ $seccount = count($rs);
?>
<ul>
<?
- while ($row = mysql_fetch_array($rs)) {
+ foreach ($rs as $row) {
print '<li><a href="browse.php?section='.$row[name].'">'.$row[name].'</a>'.
($row[description] ? (' - '.$row[description]) : '').
'</li>'."\n";
--- NEW FILE: memcache.inc ---
<?
$memcache = new Memcache();
$memcache->connect('localhost', 11211);
function cachedQuery($sql, $compress = 0) {
global $dbh;
global $memcache;
$key = md5($sql);
if ($returnVals = $memcache->get($key)) {
echo " <!-- cached($compress) $key: $sql --> ";
return $returnVals;
} else {
echo " <!-- NOT cached($compress) $key: $sql --> ";
$returnVals = array();
$resultSet = mysql_query($sql, $dbh);
while ($row = mysql_fetch_array($resultSet)) {
array_push($returnVals, $row);
}
// 5 minute cache
if ($memcache->set($key, $returnVals, $compress, 300)) {
return $returnVals;
} else {
echo " <!-- unable to set $key($compress) --> ";
return;
}
}
}
?>
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Fink-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/fink-commits