Screenshot class optimization. Defer creation of thumbnail and screenshot images until values are necessary.

This greatly speeds up the loading of the main page as we create screenshot objects to check their other internal
parameters and not output their images.
This commit is contained in:
Chris Morgan
2006-07-10 15:18:08 +00:00
committed by WineHQ
parent 6405eeafa4
commit 5f4998194a
3 changed files with 76 additions and 11 deletions

View File

@@ -120,11 +120,11 @@ if (!$aClean['iId'])
$oScreenshot = new Screenshot($obj_row->id); $oScreenshot = new Screenshot($obj_row->id);
echo '<tr valign=top><td class=color0><b>Submited image</b></td>',"\n"; echo '<tr valign=top><td class=color0><b>Submited image</b></td>',"\n";
echo '<td>'; echo '<td>';
$imgSRC = '<img width="'.$oScreenshot->oThumbnailImage->width.'" height="'.$oScreenshot->oThumbnailImage->height.'" src="../appimage.php?bQueued=true&iId='.$obj_row->id.'" />'; $imgSRC = '<img width="'.$oScreenshot->get_thumbnail_width().'" height="'.$oScreenshot->get_thumbnail_height().'" src="../appimage.php?bQueued=true&iId='.$obj_row->id.'" />';
// generate random tag for popup window // generate random tag for popup window
$randName = User::generate_passwd(5); $randName = User::generate_passwd(5);
// set image link based on user pref // set image link based on user pref
$img = '<a href="javascript:openWin(\'../appimage.php?bQueued=true&iId='.$obj_row->id.'\',\''.$randName.'\','.$oScreenshot->oScreenshotImage->width.','.($oScreenshot->oScreenshotImage->height+4).');">'.$imgSRC.'</a>'; $img = '<a href="javascript:openWin(\'../appimage.php?bQueued=true&iId='.$obj_row->id.'\',\''.$randName.'\','.$oScreenshot->get_screenshot_width().','.($oScreenshot->get_screenshot_height()+4).');">'.$imgSRC.'</a>';
if ($_SESSION['current']->isLoggedIn()) if ($_SESSION['current']->isLoggedIn())
{ {
if ($_SESSION['current']->getpref("window:screenshot") == "no") if ($_SESSION['current']->getpref("window:screenshot") == "no")

View File

@@ -98,7 +98,7 @@ if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) &&
header("Last-Modified: ".fHttpDate($iModTime)); header("Last-Modified: ".fHttpDate($iModTime));
if(!$aClean['bThumbnail']) if(!$aClean['bThumbnail'])
$oScreenshot->oScreenshotImage->output_to_browser(1); $oScreenshot->output_screenshot(false);
else else
$oScreenshot->oThumbnailImage->output_to_browser(1); $oScreenshot->output_screenshot(true);
?> ?>

View File

@@ -42,8 +42,6 @@ class Screenshot {
$oRow = mysql_fetch_object($hResult); $oRow = mysql_fetch_object($hResult);
$this->iScreenshotId = $iScreenshotId; $this->iScreenshotId = $iScreenshotId;
$this->sDescription = $oRow->description; $this->sDescription = $oRow->description;
$this->oScreenshotImage = new Image("/data/screenshots/".$oRow->url);
$this->oThumbnailImage = new Image("/data/screenshots/thumbnails/".$oRow->url);
$this->iAppId = $oRow->appId; $this->iAppId = $oRow->appId;
$this->iVersionId = $oRow->versionId; $this->iVersionId = $oRow->versionId;
$this->sUrl = $oRow->url; $this->sUrl = $oRow->url;
@@ -108,7 +106,6 @@ class Screenshot {
query_parameters($sQuery, $this->iScreenshotId); query_parameters($sQuery, $this->iScreenshotId);
return false; return false;
} }
} }
$this->screenshot($this->iScreenshotId,$this->bQueued); $this->screenshot($this->iScreenshotId,$this->bQueued);
@@ -133,6 +130,11 @@ class Screenshot {
/* we can perform better permissions checking there */ /* we can perform better permissions checking there */
if($_SESSION['current']->deleteAppData($this->iScreenshotId)) if($_SESSION['current']->deleteAppData($this->iScreenshotId))
{ {
/* make sure the screenshot and thumbnail is loaded */
/* up before we try to delete them */
$this->load_image(true);
$this->load_image(false);
$this->oScreenshotImage->delete(); $this->oScreenshotImage->delete();
$this->oThumbnailImage->delete(); $this->oThumbnailImage->delete();
unlink(appdb_fullpath("/data/screenshots/originals/".$this->iScreenshotId)); unlink(appdb_fullpath("/data/screenshots/originals/".$this->iScreenshotId));
@@ -231,6 +233,69 @@ class Screenshot {
return true; return true;
} }
/* ensure that either the thumbnail or screenshot */
/* has been loaded into memory */
function load_image($bThumbnail)
{
if($bThumbnail)
{
/* if we haven't loaded the thumbnail up yet, do so */
if(!$this->oThumbnailImage)
$this->oThumbnailImage = new Image("/data/screenshots/thumbnails/".$this->sUrl);
} else
{
/* if we haven't loaded the screenshot up yet, do so */
if(!$this->oScreenshotImage)
$this->oScreenshotImage = new Image("/data/screenshots/".$this->sUrl);
}
}
/* output the thumbnail if $bThumbnail or the full screenshot if !$bThumbnail */
/* NOTE: use this instead of calling through to this classes oScreenshot or */
/* oThumbnail objects directly to their output_*() functions */
function output_screenshot($bThumbnail)
{
$this->load_image($bThumbnail);
if($bThumbnail)
{
if($this->oThumbnailImage)
$this->oThumbnailImage->output_to_browser(1);
} else
{
if($this->oScreenshotImage)
$this->oScreenshotImage->output_to_browser(1);
}
}
/* Accessor functions for the screenshot and thumbnail images that this */
/* screenshot object encapsulates */
/* NOTE: DO NOT call like $oScreenshot->oScreenshotImage->get_width(), there is NO */
/* guarantee that oScreenshotImage will be valid */
function get_screenshot_width()
{
$this->load_image(false);
return $this->oScreenshotImage->get_width();
}
function get_screenshot_height()
{
$this->load_image(false);
return $this->oScreenshotImage->get_height();
}
function get_thumbnail_width()
{
$this->load_image(true);
return $this->oThumbnailImage->get_width();
}
function get_thumbnail_height()
{
$this->load_image(true);
return $this->oThumbnailImage->get_height();
}
function mailSubmitter($bRejected=false) function mailSubmitter($bRejected=false)
{ {
@@ -411,14 +476,14 @@ function get_thumbnail($id)
// set img tag // set img tag
$imgSRC = '<img src="'.apidb_fullurl("appimage.php"). $imgSRC = '<img src="'.apidb_fullurl("appimage.php").
'?bThumbnail=true&iId='.$id.'" alt="'.$oScreenshot->sDescription. '?bThumbnail=true&iId='.$id.'" alt="'.$oScreenshot->sDescription.
'" width="'.$oScreenshot->oThumbnailImage->get_width(). '" width="'.$oScreenshot->get_thumbnail_width().
'" height="'.$oScreenshot->oThumbnailImage->get_height().'">'; '" height="'.$oScreenshot->get_thumbnail_height().'">';
$img = '<a href="'.apidb_fullurl("appimage.php"). $img = '<a href="'.apidb_fullurl("appimage.php").
'?iId='.$id. '?iId='.$id.
'" onclick="javascript:openWin(\''.apidb_fullurl("appimage.php"). '" onclick="javascript:openWin(\''.apidb_fullurl("appimage.php").
'?iId='.$id.'\',\''.$randName.'\','. '?iId='.$id.'\',\''.$randName.'\','.
($oScreenshot->oScreenshotImage->get_width() + 20).','. ($oScreenshot->get_screenshot_width() + 20).','.
($oScreenshot->oScreenshotImage->get_height() + 6). ($oScreenshot->get_screenshot_height() + 6).
');return false;">'.$imgSRC.'</a>'; ');return false;">'.$imgSRC.'</a>';
// set image link based on user pref // set image link based on user pref