appdb/ ./appimage.php admin/adminAppDataQueue. ...

WineHQ wineowner at wine.codeweavers.com
Mon Jul 10 10:18:08 CDT 2006


ChangeSet ID:	26390
CVSROOT:	/opt/cvs-commit
Module name:	appdb
Changes by:	wineowner at winehq.org	2006/07/10 10:18:08

Modified files:
	.              : appimage.php 
	admin          : adminAppDataQueue.php 
	include        : screenshot.php 

Log message:
	Chris Morgan <cmorgan at alum.wpi.edu>
	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.

Patch: http://cvs.winehq.org/patch.py?id=26390

Old revision  New revision  Changes     Path
 1.26          1.27          +2 -2       appdb/appimage.php
 1.29          1.30          +2 -2       appdb/admin/adminAppDataQueue.php
 1.44          1.45          +72 -7      appdb/include/screenshot.php

Index: appdb/appimage.php
diff -u -p appdb/appimage.php:1.26 appdb/appimage.php:1.27
--- appdb/appimage.php:1.26	10 Jul 2006 15:18: 8 -0000
+++ appdb/appimage.php	10 Jul 2006 15:18: 8 -0000
@@ -98,7 +98,7 @@ if (isset($_SERVER['HTTP_IF_MODIFIED_SIN
 header("Last-Modified: ".fHttpDate($iModTime));
 
 if(!$aClean['bThumbnail'])
-    $oScreenshot->oScreenshotImage->output_to_browser(1);
+    $oScreenshot->output_screenshot(false);
 else
-    $oScreenshot->oThumbnailImage->output_to_browser(1);
+    $oScreenshot->output_screenshot(true);
 ?>
Index: appdb/admin/adminAppDataQueue.php
diff -u -p appdb/admin/adminAppDataQueue.php:1.29 appdb/admin/adminAppDataQueue.php:1.30
--- appdb/admin/adminAppDataQueue.php:1.29	10 Jul 2006 15:18: 8 -0000
+++ appdb/admin/adminAppDataQueue.php	10 Jul 2006 15:18: 8 -0000
@@ -120,11 +120,11 @@ if (!$aClean['iId'])
            $oScreenshot = new Screenshot($obj_row->id);
            echo '<tr valign=top><td class=color0><b>Submited image</b></td>',"\n";
            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
            $randName = User::generate_passwd(5);
            // 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']->getpref("window:screenshot") == "no")
Index: appdb/include/screenshot.php
diff -u -p appdb/include/screenshot.php:1.44 appdb/include/screenshot.php:1.45
--- appdb/include/screenshot.php:1.44	10 Jul 2006 15:18: 8 -0000
+++ appdb/include/screenshot.php	10 Jul 2006 15:18: 8 -0000
@@ -42,8 +42,6 @@ class Screenshot {
                 $oRow = mysql_fetch_object($hResult);
                 $this->iScreenshotId = $iScreenshotId;
                 $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->iVersionId = $oRow->versionId;
                 $this->sUrl = $oRow->url;
@@ -108,7 +106,6 @@ class Screenshot {
                     query_parameters($sQuery, $this->iScreenshotId);
                     return false;
                 }
-                 
             }
 
             $this->screenshot($this->iScreenshotId,$this->bQueued);
@@ -133,6 +130,11 @@ class Screenshot {
         /* we can perform better permissions checking there */
         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->oThumbnailImage->delete();
             unlink(appdb_fullpath("/data/screenshots/originals/".$this->iScreenshotId));
@@ -231,6 +233,69 @@ class Screenshot {
         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)
     {
@@ -411,14 +476,14 @@ function get_thumbnail($id)
     // set img tag        
     $imgSRC  = '<img src="'.apidb_fullurl("appimage.php").
                '?bThumbnail=true&iId='.$id.'" alt="'.$oScreenshot->sDescription.
-               '" width="'.$oScreenshot->oThumbnailImage->get_width().
-               '" height="'.$oScreenshot->oThumbnailImage->get_height().'">';
+               '" width="'.$oScreenshot->get_thumbnail_width().
+               '" height="'.$oScreenshot->get_thumbnail_height().'">';
     $img = '<a href="'.apidb_fullurl("appimage.php").
            '?iId='.$id.
            '" onclick="javascript:openWin(\''.apidb_fullurl("appimage.php").
            '?iId='.$id.'\',\''.$randName.'\','.
-           ($oScreenshot->oScreenshotImage->get_width() + 20).','.
-           ($oScreenshot->oScreenshotImage->get_height() + 6).
+           ($oScreenshot->get_screenshot_width() + 20).','.
+           ($oScreenshot->get_screenshot_height() + 6).
            ');return false;">'.$imgSRC.'</a>';
 
     // set image link based on user pref



More information about the wine-cvs mailing list