ChangeSet ID: 30972 CVSROOT: /opt/cvs-commit Module name: appdb Changes by: wineowner@winehq.org 2007/03/15 18:43:46
Modified files: include : appData.php version.php unit_test : run_tests.php Added files: unit_test : test_appData.php
Log message: Alexander Nicolaysen Sørnes alex@thehandofagony.com Fix appData::listSubmittedBy() to run faster. Add a unit test for appData::listSubmittedBy()
Patch: http://cvs.winehq.org/patch.py?id=30972
Old revision New revision Changes Path 1.9 1.10 +18 -16 appdb/include/appData.php 1.105 1.106 +6 -1 appdb/include/version.php 1.11 1.12 +2 -0 appdb/unit_test/run_tests.php Added 1.1 +0 -0 appdb/unit_test/test_appData.php
Index: appdb/include/appData.php diff -u -p appdb/include/appData.php:1.9 appdb/include/appData.php:1.10 --- appdb/include/appData.php:1.9 15 Mar 2007 23:43:46 -0000 +++ appdb/include/appData.php 15 Mar 2007 23:43:46 -0000 @@ -39,22 +39,17 @@ class appData
function listSubmittedBy($iUserId, $bQueued = true) { - $hResult = query_parameters("SELECT appData.TYPE, appData.appId, - appData.versionId, appData.description, appData.submitTime, - appFamily.appName, appVersion.versionName FROM appData, - appFamily, appVersion - WHERE (appFamily.appId = appData.appId OR - (appData.versionId = appVersion.versionId AND appFamily.appId = - appVersion.appId)) AND (appFamily.queued = '?' OR - appVersion.queued = '?') AND appData.submitterId = '?' AND + $hResult = query_parameters("SELECT * FROM appData WHERE + appData.submitterId = '?' + AND appData.queued = '?' ORDER BY appData.id", - "false", "false", $iUserId, $bQueued ? "true" : "false"); + $iUserId, $bQueued ? "true" : "false");
if(!$hResult || !mysql_num_rows($hResult)) return false;
- $sReturn .= html_table_begin("width="100%" align="center""); + $sReturn = html_table_begin("width="100%" align="center""); $sReturn .= html_tr(array( "Version", "Type", @@ -64,13 +59,19 @@ class appData
for($i = 1; $oRow = mysql_fetch_object($hResult); $i++) { + if($oRow->versionId) + { + $oVersion = new version($oRow->versionId); + $sLink = "<a href="".$oVersion->objectMakeUrl()."">". + $oVersion->fullName($oVersion->iVersionId)."</a>"; + } else + { + $oApp = new application($this->appId); + $sLink = $oApp->objectMakeLink(); + } $sReturn .= html_tr(array( - $oRow->versionId ? - "<a href="".BASE."appview.php?iVersionId=$oRow->versionId">". - "$oRow->appName: $oRow->versionName</a>" : - "<a href="".BASE."appview.php?iAppId=$oRow->appId">". - "$oRow->appName</a>", - $oRow->TYPE, + $sLink, + $oRow->type, $oRow->description, print_date(mysqltimestamp_to_unixtimestamp($oRow->submitTime))), ($i % 2) ? "color0" : "color1"); @@ -79,6 +80,7 @@ class appData $sReturn .= html_table_end("");
return $sReturn; + }
/* Get appData for a given version/application, optionally filter by type */ Index: appdb/include/version.php diff -u -p appdb/include/version.php:1.105 appdb/include/version.php:1.106 --- appdb/include/version.php:1.105 15 Mar 2007 23:43:46 -0000 +++ appdb/include/version.php 15 Mar 2007 23:43:46 -0000 @@ -1133,9 +1133,14 @@ class Version { return FALSE; }
+ function objectMakeUrl() + { + return BASE."appview.php?iVersionId=$this->iVersionId"; + } + function objectMakeLink() { - $sLink = "<a href="".BASE."appview.php?iVersionId=$this->iVersionId">". + $sLink = "<a href="".$this->objectMakeUrl()."">". $this->sName."</a>"; return $sLink; } Index: appdb/unit_test/run_tests.php diff -u -p appdb/unit_test/run_tests.php:1.11 appdb/unit_test/run_tests.php:1.12 --- appdb/unit_test/run_tests.php:1.11 15 Mar 2007 23:43:46 -0000 +++ appdb/unit_test/run_tests.php 15 Mar 2007 23:43:46 -0000 @@ -26,4 +26,6 @@ echo "\n"; include_once("test_url.php"); echo "\n"; include_once("test_om_objects.php"); +echo "\n"; +include_once("test_appData.php"); ?> Index: appdb/unit_test/test_appData.php diff -u -p /dev/null appdb/unit_test/test_appData.php:1.1 --- /dev/null 15 Mar 2007 23:43:46 -0000 +++ appdb/unit_test/test_appData.php 15 Mar 2007 23:43:46 -0000 @@ -0,0 +1,51 @@ +<?php + +require_once("path.php"); +require_once("test_common.php"); +require_once(BASE."include/appData.php"); +require_once(BASE."include/downloadurl.php"); + +function test_appData_listSubmittedBy() +{ + test_start(__FUNCTION__); + + global $test_email, $test_password; + if(!$oUser = create_and_login_user()) + { + echo "Failed to create and log in user\n"; + return FALSE; + } + + /* Create a queued appData entry */ + $oDownloadUrl = new downloadurl; + + $oDownloadUrl->sUrl = "http://www.microsoft.com/windowsmedia"; + $oDownloadUrl->sDescription = "Download Meida Player"; + $oDownloadUrl->iVersionId = 1; + + $oDownloadUrl->create(); + + $shReturn = appData::listSubmittedBy($oUser->iUserId, true); + + /* There should be two lines; one header and one for the downloadurl */ + $iExpected = 2; + $iReceived = substr_count($shReturn, "</tr>"); + if($iExpected != $iReceived) + { + echo "Got $iReceived rows instead of $iExpected.\n"; + return FALSE; + } + + /* Clean up */ + $oDownloadUrl->delete(); + $oUser->delete(); + + return TRUE; +} + +if(!test_appData_listSubmittedBy()) + echo "test_appData_listSubmittedBy() failed!\n"; +else + echo "test_appData_listSubmittedBy() passed\n"; + +?>