ChangeSet ID: 26404
CVSROOT: /opt/cvs-commit
Module name: appdb
Changes by: wineowner(a)winehq.org 2006/07/10 22:48:40
Modified files:
. : appimage.php
Log message:
Chris Morgan <cmorgan(a)alum.wpi.edu>
Clean up appimage code removing a bunch of redundant code and removing a query for each image that is actually output
to the browser
Patch: http://cvs.winehq.org/patch.py?id=26404
Old revision New revision Changes Path
1.27 1.28 +19 -47 appdb/appimage.php
Index: appdb/appimage.php
diff -u -p appdb/appimage.php:1.27 appdb/appimage.php:1.28
--- appdb/appimage.php:1.27 11 Jul 2006 3:48:40 -0000
+++ appdb/appimage.php 11 Jul 2006 3:48:40 -0000
@@ -28,59 +28,31 @@ header("Pragma: ");
if(!$_SESSION['current']->canViewImage($aClean['iId']))
util_show_error_page_and_exit("Insufficient privileges.");
-if ($aClean['sREQUEST_METHOD']='HEAD')
+$oScreenshot = new Screenshot($aClean['iId']);
+$fImage = fopen(appdb_fullpath("data/screenshots/".$oScreenshot->sUrl), "rb");
+
+/* if we can open the image we should get its last modified time and read */
+/* a few bytes from its header information and close it */
+if($fImage)
{
- /* WARNING! optimization of logic in include/screenshots.php */
- if (sscanf($aClean['iId'],"%d", &$iId) < 1)
- util_show_error_page_and_exit("Bad parameter");
-
- $hResult = query_parameters("SELECT id, url FROM appData
- WHERE id = '?'
- AND type = 'image' LIMIT 1", $iId);
- $fImage = 0;
- if($hResult)
- {
- $oRow = mysql_fetch_object($hResult);
-
- /* we need to use the url field from appData, this is the name of the file */
- /* in the filesystem */
- $fImage = fopen(appdb_fullpath("data/screenshots/".$oRow->url), "rb");
- }
-
- /* if the query failed or if we didn't find the image, we should */
- /* report a 404 to the browser */
- if(!$hResult || !$fImage)
- {
- header("404 No such image");
- exit;
- }
$fstat_val = fstat($fImage);
$iModTime = $fstat_val['mtime'];
- $sMagic = fread($fImage,8);
+ $sMagic = fread($fImage, 8); /* read 8 bytes from the header, that lets us idenfity the type of
+ image without loading it */
fclose($fImage); /* don't leave the fopened image open */
- /* identify what kind of image this is, if we can't identify it */
- /* we should report that its a bad image */
- if (strcmp("\x89PNG\r\n\x1A\n",$sMagic)==0)
- {
- header("Content-Type: image/png");
- } else if (preg_match("^\xD8\xFF^",$sMagic)) {
- header("Content-Type: image/jpeg");
- } else {
- header("500 Bad image format");
- exit;
- }
- header("Cache-Control: public");
- header("Expires: ");
- header("Last-Modified: ".fHttpDate($iModTime));
}
-$oScreenshot = new Screenshot($aClean['iId']);
-
-/* at this point, we know that .../screenshots/$oScreenshot->sUrl and
- * .../screenshots/thumbnails/$oScreenshot->sUrl both exist as normally
- * they would both be created at the same time. */
-$fstat_val = stat(appdb_fullpath("data/screenshots/".$oScreenshot->sUrl));
-$iModTime = $fstat_val['mtime'];
+/* identify what kind of image this is, if we can't identify it */
+/* we should report that its a bad image */
+if (strcmp("\x89PNG\r\n\x1A\n", $sMagic)==0)
+{
+ header("Content-Type: image/png");
+} else if (preg_match("^\xD8\xFF^", $sMagic)) {
+ header("Content-Type: image/jpeg");
+} else {
+ header("500 Bad image format");
+ exit;
+}
header("Cache-Control: public");
header("Expires: ");
ChangeSet ID: 26402
CVSROOT: /opt/cvs-commit
Module name: appdb
Changes by: wineowner(a)winehq.org 2006/07/10 22:41:57
Modified files:
include : util.php
Log message:
Chris Morgan <cmorgan(a)alum.wpi.edu>
Speed up outputTopXRowAppsFromRating() by earlying out if we have enough applications to fill our required amount.
This saves a database query for each top X table. Also rename $num_apps to $iNum_apps
Patch: http://cvs.winehq.org/patch.py?id=26402
Old revision New revision Changes Path
1.69 1.70 +8 -5 appdb/include/util.php
Index: appdb/include/util.php
diff -u -p appdb/include/util.php:1.69 appdb/include/util.php:1.70
--- appdb/include/util.php:1.69 11 Jul 2006 3:41:57 -0000
+++ appdb/include/util.php 11 Jul 2006 3:41:57 -0000
@@ -301,11 +301,11 @@ function outputTopXRow($oRow)
}
/* Output the rows for the Top-X tables on the main page */
-function outputTopXRowAppsFromRating($rating, $num_apps)
+function outputTopXRowAppsFromRating($rating, $iNum_apps)
{
/* clean the input values so we can continue to use query_appdb() */
$rating = mysql_real_escape_string($rating);
- $num_apps = mysql_real_escape_string($num_apps);
+ $iNum_apps = mysql_real_escape_string($iNum_apps);
/* list of appIds we've already output, so we don't output */
/* them again when filling in any empty spots in the list */
@@ -318,14 +318,17 @@ function outputTopXRowAppsFromRating($ra
GROUP BY appVotes.appId
ORDER BY c DESC
LIMIT ?";
- $hResult = query_parameters($sQuery, $rating, $num_apps);
- $num_apps-=mysql_num_rows($hResult); /* take away the rows we are outputting here */
+ $hResult = query_parameters($sQuery, $rating, $iNum_apps);
+ $iNum_apps-=mysql_num_rows($hResult); /* take away the rows we are outputting here */
while($oRow = mysql_fetch_object($hResult))
{
array_push($appIdArray, $oRow->appId); /* keep track of the apps we've already output */
outputTopXRow($oRow);
}
+ /* if we have no more app entries we should stop now and save ourselves a query */
+ if(!$iNum_apps) return;
+
/* if we have any empty spots in the list, get these from applications with images */
$sQuery = "SELECT DISTINCT appVersion.appId as appId, appVersion.versionId
FROM appVersion, appData
@@ -338,7 +341,7 @@ function outputTopXRowAppsFromRating($ra
foreach($appIdArray as $key=>$value)
$sQuery.="AND appVersion.appId != '".$value."' ";
- $sQuery.=" LIMIT $num_apps";
+ $sQuery.=" LIMIT $iNum_apps";
/* get the list that will fill the empty spots */
$hResult = query_appdb($sQuery);