From 0a9f8cc15521166930ab535d4f234b08bdc930f7 Mon Sep 17 00:00:00 2001 From: Chris Morgan Date: Sun, 9 Jul 2006 00:48:33 +0000 Subject: [PATCH] Performance improvements to version and application classes. Reduce the amount of queries to what is necessary during object creation. The only use of all but one of the arrays we were fetching during version and application construction was in ::delete() so we can just retrieve them there. Speed screenshot class up by only querying for necessary columns, not select * --- admin/adminAppQueue.php | 2 +- include/application.php | 38 ++++--- include/comment.php | 10 ++ include/screenshot.php | 7 +- include/version.php | 229 ++++++++++++++++++++-------------------- 5 files changed, 148 insertions(+), 138 deletions(-) diff --git a/admin/adminAppQueue.php b/admin/adminAppQueue.php index 062780a..af64f6a 100644 --- a/admin/adminAppQueue.php +++ b/admin/adminAppQueue.php @@ -117,7 +117,7 @@ function display_move_test_to_versions_table($aVersionsIds,$icurrentVersionId) echo " ".util_trim_description($oVersion->sDescription)."\n"; echo " ".$oVersion->sTestedRating."\n"; echo " ".$oVersion->sTestedRelease."\n"; - echo " ".sizeof($oVersion->aCommentsIds)."\n"; + echo " ".Comment::get_comment_count_for_versionid($oVersion->iVersionId)."\n"; echo "\n\n"; $c++; diff --git a/include/application.php b/include/application.php index e471d0e..cc5685f 100644 --- a/include/application.php +++ b/include/application.php @@ -25,7 +25,6 @@ class Application { var $sSubmitTime; var $iSubmitterId; var $aVersionsIds; // an array that contains the versionId of every version linked to this app. - var $aUrlsIds; // an array that contains the screenshotId of every url linked to this version /** * constructor, fetches the data. @@ -77,24 +76,6 @@ class Application { $this->aVersionsIds[] = $oRow->versionId; } } - - - /* - * We fetch urlsIds. - */ - $this->aUrlsIds = array(); - $sQuery = "SELECT id - FROM appData - WHERE type = 'url' - AND appId = '?'"; - - if($hResult = query_parameters($sQuery, $iAppId)) - { - while($oRow = mysql_fetch_object($hResult)) - { - $this->aUrlsIds[] = $oRow->id; - } - } } } @@ -219,7 +200,24 @@ class Application { $oVersion = new Version($iVersionId); $oVersion->delete($bSilent); } - foreach($this->aUrlsIds as $iUrlId) + + + /* fetch urlsIds */ + $aUrlsIds = array(); + $sQuery = "SELECT id + FROM appData + WHERE type = 'url' + AND appId = '?'"; + + if($hResult = query_parameters($sQuery, $this->iAppId)) + { + while($oRow = mysql_fetch_object($hResult)) + { + $aUrlsIds[] = $oRow->id; + } + } + + foreach($aUrlsIds as $iUrlId) { $oUrl = new Url($iUrlId); $oUrl->delete($bSilent); diff --git a/include/comment.php b/include/comment.php index 04c19f2..f85d473 100644 --- a/include/comment.php +++ b/include/comment.php @@ -187,6 +187,16 @@ class Comment { return false; } + function get_comment_count_for_versionid($iVersionId) + { + $sQuery = "SELECT count(*) as cnt from appComments where versionId = '?'"; + $hResult = query_parameters($sQuery, $iVersionId); + if(!$hResult) return 0; + + $oRow = mysql_fetch_object($hResult); + return $oRow->cnt; + } + /** * class static functions */ diff --git a/include/screenshot.php b/include/screenshot.php index 069cbab..a80e28c 100644 --- a/include/screenshot.php +++ b/include/screenshot.php @@ -307,12 +307,13 @@ class Screenshot { * * $bFormatting == false turns off all extranious formatting applied to the returned image html */ -function get_screenshot_img($iAppId = null, $iVersionId = null, $bFormatting = true) +function get_screenshot_img($iAppId = null, $iVersionId = null, + $bFormatting = true) { // we want a random screenshots for this app if($iAppId && !$iVersionId) { - $hResult = query_parameters("SELECT appData.*, RAND() AS rand + $hResult = query_parameters("SELECT appData.id, appData.description, RAND() AS rand FROM appData, appVersion WHERE appData.versionId = appVersion.versionId AND appVersion.appId = '?' @@ -321,7 +322,7 @@ function get_screenshot_img($iAppId = null, $iVersionId = null, $bFormatting = t ORDER BY rand", $iAppId); } else if ($iVersionId) // we want a random screenshot for this version { - $hResult = query_parameters("SELECT *, RAND() AS rand + $hResult = query_parameters("SELECT id, description, RAND() AS rand FROM appData WHERE versionId = '?' AND type = 'image' diff --git a/include/version.php b/include/version.php index 2dbd83b..05ce02c 100644 --- a/include/version.php +++ b/include/version.php @@ -25,13 +25,6 @@ class Version { var $iSubmitterId; var $sDate; var $sQueued; - var $aNotesIds; // an array that contains the noteId of every note linked to this version - var $aCommentsIds; // an array that contains the commentId of every comment linked to this version - var $aScreenshotsIds; // an array that contains the screenshotId of every screenshot linked to this version - var $aUrlsIds; // an array that contains the screenshotId of every url linked to this version - var $aBuglinkIds; // an array that contains the buglinkId of every bug linked to this version - var $aTestingIds; // an array that contains the testingId of every test result linked to this version - var $aMonitorIds; // an array that contains the monitorId of every monitor linked to this version /** * constructor, fetches the data. @@ -67,105 +60,6 @@ class Version { $this->sQueued = $oRow->queued; } } - - /* - * We fetch notesIds. - */ - $this->aNotesIds = array(); - $sQuery = "SELECT noteId - FROM appNotes - WHERE versionId = '?'"; - if($hResult = query_parameters($sQuery, $iVersionId)) - { - while($oRow = mysql_fetch_object($hResult)) - { - $this->aNotesIds[] = $oRow->noteId; - } - } - - /* - * We fetch commentsIds. - */ - $this->aCommentsIds = array(); - $sQuery = "SELECT commentId - FROM appComments - WHERE versionId = '?'"; - if($hResult = query_parameters($sQuery, $iVersionId)) - { - while($oRow = mysql_fetch_object($hResult)) - { - $this->aCommentsIds[] = $oRow->commentId; - } - } - - - /* - * We fetch screenshotsIds and urlsIds. - */ - $this->aScreenshotsIds = array(); - $this->aUrlsIds = array(); - $sQuery = "SELECT id, type - FROM appData - WHERE versionId = '?'"; - - if($hResult = query_parameters($sQuery, $iVersionId)) - { - while($oRow = mysql_fetch_object($hResult)) - { - if($oRow->type="image") - $this->aScreenshotsIds[] = $oRow->id; - else - $this->aUrlsIds[] = $oRow->id; - } - } - - /* - * We fetch Bug linkIds. - */ - $this->aBuglinkIds = array(); - $sQuery = "SELECT * - FROM buglinks - WHERE versionId = '?' - ORDER BY bug_id"; - if($hResult = query_parameters($sQuery, $iVersionId)) - { - while($oRow = mysql_fetch_object($hResult)) - { - $this->aBuglinkIds[] = $oRow->linkId; - } - } - - /* - * We fetch Test Results Ids. - */ - $this->aTestingIds = array(); - $sQuery = "SELECT * - FROM testResults - WHERE versionId = '?' - ORDER BY testingId"; - if($hResult = query_parameters($sQuery, $iVersionId)) - { - while($oRow = mysql_fetch_object($hResult)) - { - $this->aTestingIds[] = $oRow->testingId; - } - } - - /* - * We fetch monitor Ids. - */ - $this->aMonitorIds = array(); - $sQuery = "SELECT * - FROM appMonitors - WHERE versionId = '?' - ORDER BY monitorId"; - if($hResult = query_parameters($sQuery, $iVersionId)) - { - while($oRow = mysql_fetch_object($hResult)) - { - $this->aMonitorIds[] = $oRow->monitorId; - } - } } } @@ -287,43 +181,129 @@ class Version { if(!$_SESSION['current']->canDeleteVersion($this)) return false; + /* fetch notesIds */ + $aNotesIds = array(); + $sQuery = "SELECT noteId + FROM appNotes + WHERE versionId = '?'"; + if($hResult = query_parameters($sQuery, $this->iVersionId)) + { + while($oRow = mysql_fetch_object($hResult)) + { + $aNotesIds[] = $oRow->noteId; + } + } + /* remove all of the items this version contains */ - foreach($this->aNotesIds as $iNoteId) + foreach($aNotesIds as $iNoteId) { $oNote = new Note($iNoteId); $oNote->delete($bSilent); } - foreach($this->aCommentsIds as $iCommentId) + + + /* We fetch commentsIds. */ + $aCommentsIds = array(); + $sQuery = "SELECT commentId + FROM appComments + WHERE versionId = '?'"; + if($hResult = query_parameters($sQuery, $this->iVersionId)) + { + while($oRow = mysql_fetch_object($hResult)) + { + $aCommentsIds[] = $oRow->commentId; + } + } + + foreach($aCommentsIds as $iCommentId) { $oComment = new Comment($iCommentId); $oComment->delete($bSilent); } - foreach($this->aScreenshotsIds as $iScreenshotId) + + + /* fetch screenshotsIds and urlsIds */ + $aScreenshotsIds = array(); + $aUrlsIds = array(); + $sQuery = "SELECT id, type + FROM appData + WHERE versionId = '?'"; + + if($hResult = query_parameters($sQuery, $this->iVersionId)) + { + while($oRow = mysql_fetch_object($hResult)) + { + if($oRow->type="image") + $aScreenshotsIds[] = $oRow->id; + else + $aUrlsIds[] = $oRow->id; + } + } + + foreach($aScreenshotsIds as $iScreenshotId) { $oScreenshot = new Screenshot($iScreenshotId); $oScreenshot->delete($bSilent); } - foreach($this->aUrlsIds as $iUrlId) + foreach($aUrlsIds as $iUrlId) { $oUrl = new Url($iUrlId); $oUrl->delete($bSilent); } + + + foreach($this->aBuglinkIds as $iBug_id) { $oBug = new bug($iBug_id); $oBug->delete($bSilent); } - foreach($this->aTestingIds as $iTestId) + + + + + /* fetch Test Results Ids */ + $aTestingIds = array(); + $sQuery = "SELECT * + FROM testResults + WHERE versionId = '?' + ORDER BY testingId"; + if($hResult = query_parameters($sQuery, $this->iVersionId)) + { + while($oRow = mysql_fetch_object($hResult)) + { + $aTestingIds[] = $oRow->testingId; + } + } + + foreach($aTestingIds as $iTestId) { $oTest = new testData($iTestId); $oTest->delete($bSilent); } - foreach($this->aMonitorIds as $iMonitorId) + + + /* fetch monitor Ids */ + $aMonitorIds = array(); + $sQuery = "SELECT * + FROM appMonitors + WHERE versionId = '?' + ORDER BY monitorId"; + if($hResult = query_parameters($sQuery, $this->iVersionId)) + { + while($oRow = mysql_fetch_object($hResult)) + { + $aMonitorIds[] = $oRow->monitorId; + } + } + + foreach($aMonitorIds as $iMonitorId) { $oMonitor = new Monitor($iMonitorId); $oMonitor->delete($bSilent); } + // remove any maintainers for this version so we don't orphan them $hResult = query_parameters("DELETE from appMaintainers WHERE versionId='?'", $this->iVersionId); if(!$hResult) @@ -520,6 +500,27 @@ class Version { mail_appdb($sEmail, $sSubject ,$sMsg); } + function get_buglink_ids() + { + /* + * We fetch Bug linkIds. + */ + $aBuglinkIds = array(); + $sQuery = "SELECT * + FROM buglinks + WHERE versionId = '?' + ORDER BY bug_id"; + if($hResult = query_parameters($sQuery, $this->iVersionId)) + { + while($oRow = mysql_fetch_object($hResult)) + { + $aBuglinkIds[] = $oRow->linkId; + } + } + + return $aBuglinkIds; + } + /* output html and the current versions information for editing */ /* if $editParentApplication is true that means we need to display fields */ /* to let the user change the parent application of this version */ @@ -802,7 +803,7 @@ class Version { echo html_frame_end(); - view_version_bugs($this->iVersionId, $this->aBuglinkIds); + view_version_bugs($this->iVersionId, $this->get_buglink_ids()); /* display the notes for the application */ $hNotes = query_parameters("SELECT noteId FROM appNotes WHERE versionId = '?'", @@ -901,7 +902,7 @@ class Version { echo " ".util_trim_description($oVersion->sDescription)."\n"; echo " ".$oVersion->sTestedRating."\n"; echo " ".$oVersion->sTestedRelease."\n"; - echo " ".sizeof($oVersion->aCommentsIds)."\n"; + echo " ".Comment::get_comment_count_for_versionid($oVersion->iVersionId)."\n"; echo "\n\n"; $c++;