mail[Wesnoth-commits] r28574 - in /branches/resources/tests.wesnoth.org: autotester/ include/ smarty_workdir/templates/


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by paniemin on August 14, 2008 - 08:14:
Author: suokko
Date: Thu Aug 14 07:38:56 2008
New Revision: 28574

URL: http://svn.gna.org/viewcvs/wesnoth?rev=28574&view=rev
Log:
* Added paginate class to create paging info for template
* Optimized database usage with better quaries and some index aditions.

Added:
    branches/resources/tests.wesnoth.org/include/Paginate.php   (with props)
Modified:
    branches/resources/tests.wesnoth.org/autotester/run_unit_tests.sh
    branches/resources/tests.wesnoth.org/include/Build.php
    branches/resources/tests.wesnoth.org/include/DBCreator.php
    branches/resources/tests.wesnoth.org/include/TestResult.php
    branches/resources/tests.wesnoth.org/smarty_workdir/templates/footer.tpl

Modified: branches/resources/tests.wesnoth.org/autotester/run_unit_tests.sh
URL: 
http://svn.gna.org/viewcvs/wesnoth/branches/resources/tests.wesnoth.org/autotester/run_unit_tests.sh?rev=28574&r1=28573&r2=28574&view=diff
==============================================================================
--- branches/resources/tests.wesnoth.org/autotester/run_unit_tests.sh 
(original)
+++ branches/resources/tests.wesnoth.org/autotester/run_unit_tests.sh Thu Aug 
14 07:38:56 2008
@@ -19,5 +19,5 @@
 export DISPLAY=:0.0
 
 cd $SVNDIR
-nice php -f ${AUTOTESTDIR}/run_unit_tests.php $WEBDIR
-# > $FULL_PATH/err.log
+nice php -f ${AUTOTESTDIR}/run_unit_tests.php $WEBDIR 
+#> $FULL_PATH/err.log

Modified: branches/resources/tests.wesnoth.org/include/Build.php
URL: 
http://svn.gna.org/viewcvs/wesnoth/branches/resources/tests.wesnoth.org/include/Build.php?rev=28574&r1=28573&r2=28574&view=diff
==============================================================================
--- branches/resources/tests.wesnoth.org/include/Build.php (original)
+++ branches/resources/tests.wesnoth.org/include/Build.php Thu Aug 14 
07:38:56 2008
@@ -11,20 +11,6 @@
 
    See the COPYING file for more details.
 */
-
-/*
-   Copyright (C) 2008 by Pauli Nieminen <paniemin@xxxxxxxxx>
-   Part of the Battle for Wesnoth Project http://www.wesnoth.org/
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License version 2
-   or at your option any later version.
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY.
-
-   See the COPYING file for more details.
-*/
-
 
 class Build {
        private $db;
@@ -86,7 +72,7 @@
 
        public function fetchLast()
        {
-               $this->fetch('ORDER BY id DESC');
+               $this->fetch('WHERE id=(SELECT MAX(id) FROM builds)');
        }
 
        public function fetchBuildById($id)
@@ -96,8 +82,11 @@
 
        private static function fetchVisibleBuilds($page, $builds_per_page)
        {
-               return self::multiFetch('ORDER BY id DESC LIMIT ?,?', 
+               $ret = self::multiFetch('ORDER BY id DESC LIMIT ?,?', 
                        array(($page-1)*$builds_per_page, $builds_per_page));
+
+               TestResult::fetchResultsForBuilds($ret);
+               return $ret;
        }
 
        private static function getNumberOfVisiblePages($builds_per_page)
@@ -249,6 +238,11 @@
                }
        }
 
+       public function setResult(TestResult &$result)
+       {
+               $this->result = $result;
+       }
+
        private function getErrorStatistics()
        {
                $ret = array();
@@ -262,49 +256,21 @@
        public static function getVisibleBuilds(ParameterValidator 
$user_params)
        {
                $ret = array();
-               $builds_per_page = 6; // TODO: get from config
-               $ret['paginate']['number_of_pages']     = 
self::getNumberOfVisiblePages($builds_per_page);
-
+               $builds_per_page = 18; // TODO: get from config
+               $number_of_vissible_pages = 5;
                $page = $user_params->getInt('page', 1);
-               if ($page < 0)
-                       $page = 1;
-               if ($page > $ret['paginate']['number_of_pages'])
-                       $page = $ret['paginate']['number_of_pages'];
-               
-               $ret['paginate']['page'] = $page;
-
-               $ret['paginate']['link'] = 'build_history.php?page=';
-               $visible = 5;
-               $visible_minus = 0;
-               $start = $page - floor(($visible-1)/2);
-               if ($start <= 1)
-               {
-                       $start = 1;
-                       $visible_minus = 1;
-               }
-               $last = $start + $visible + $visible_minus;
-               if ($last >= $ret['paginate']['number_of_pages'] + 1)
-               {
-                       $last = $ret['paginate']['number_of_pages'] + 1;
-                       $start = $last - $visible - 1;
-                       if ($start < 1)
-                               $start = 1;
-               }
-               $ret['paginate']['first_page'] = $start; 
-               $ret['paginate']['last_page'] = $last; 
-               $ret['paginate']['visible'] = $last - $start; 
-               
+               $number_of_pages        = 
self::getNumberOfVisiblePages($builds_per_page);
+
+               $pager = new Paginate('build_history.php?page=', $page, 
$number_of_pages, $number_of_vissible_pages);
+
+               $ret['paginate'] = $pager->make();
 
                $ret['builds'] = array();
-               $builds = self::fetchVisibleBuilds($page, $builds_per_page);
+               $builds = self::fetchVisibleBuilds($ret['paginate']['page'], 
$builds_per_page);
                foreach($builds as $build)
                {
                        $ret['builds'][] = $build->getBuildStats();
                }
-
-
-
-
                return $ret;
        }
 
@@ -342,5 +308,27 @@
                return  array('builds' => array($this->getBuildStats()),
                                          'errors'                      => 
$this->getErrorStatistics());
        }
+
+       public function pruneOldBuilds()
+       {
+               $query = 'SELECT b1.id 
+                                 FROM builds b1 LEFT JOIN test_results as r1 
ON b1.id=r1.build_id
+                                                                LEFT JOIN 
test_errors as e1 ON b1.id=e1.before_id
+                                                                LEFT JOIN 
test_errors as e2 ON b1.id=e1.last_id,
+                                          builds b2 LEFT JOIN test_results 
as r2 ON b2.id=r2.build_id
+                                 WHERE b1.time < ?
+                                          AND b1.status = b2.status 
+                                          AND b1.error_msg = b2.error_msg 
+                                          AND (b1.id = b2.id+1)
+                                          AND (e1.id IS NULL AND b1.id IS 
NOT NULL)
+                                          AND ((r1.id IS NULL AND r2.id IS 
NULL) 
+                                                       OR (r1.result = 
r2.result 
+                                                               AND 
r1.assertions_passed=r2.assertions_passed 
+                                                               AND 
r1.assertions_failed=r2.assertions_failed))';
+
+               $_2dayes = 2*24*3600;  // TODO: get from Config
+               $result = $this->db->Execute($query, 
array($this->db->DBTimeStamp(time()-$_2dayes)));
+//             var_dump($result->GetAll());
+       }
 }
 ?>

Modified: branches/resources/tests.wesnoth.org/include/DBCreator.php
URL: 
http://svn.gna.org/viewcvs/wesnoth/branches/resources/tests.wesnoth.org/include/DBCreator.php?rev=28574&r1=28573&r2=28574&view=diff
==============================================================================
--- branches/resources/tests.wesnoth.org/include/DBCreator.php (original)
+++ branches/resources/tests.wesnoth.org/include/DBCreator.php Thu Aug 14 
07:38:56 2008
@@ -62,7 +62,7 @@
                $this->field_name = $field_name;
                $this->type = $type;
                if (empty($key_name))
-                       $key_name = $field_name;
+                       $key_name = 
preg_replace('/^`([^`]*)`.*$/','$1',$field_name);
                $this->key_name = $key_name;
        }
        public function getCreateSQL()
@@ -73,7 +73,7 @@
        public function match_and_alter($db, &$create_sql, $table_name)
        {
                $m = array();
-               $needle = "/^.*$this->type (`$this->key_name`)? 
\\(`$this->field_name`\\).*$/im";
+               $needle = "/^.*$this->type (`$this->key_name`)? 
\\($this->field_name\\).*$/im";
                if (!preg_match($needle,$create_sql))
                {
 //                     echo "$needle\n$create_sql\n";
@@ -315,7 +315,7 @@
                $configtable = new DBTable('configs', 'InnoDB');
                $configtable->addChild(new DBField('name', 'VARCHAR(255) NOT 
NULL'));
                $configtable->addChild(new DBField('value', 'VARCHAR(255) NOT 
NULL'));
-               $configtable->addChild(new DBIndex('name', 'PRIMARY KEY'));
+               $configtable->addChild(new DBIndex('`name`', 'PRIMARY KEY'));
                $this->format->addChild($configtable);
 
                $buildstable = new DBTable('builds', 'InnoDB');
@@ -324,8 +324,9 @@
                $buildstable->addChild(new DBField('time', 'TIMESTAMP NOT 
NULL', 'CURRENT_TIMESTAMP'));
                $buildstable->addChild(new DBField('status', 'INT NOT NULL'));
                $buildstable->addChild(new DBField('error_msg', 'BLOB NOT 
NULL'));
-               $buildstable->addChild(new DBIndex('id', 'PRIMARY KEY'));
-               $buildstable->addChild(new DBIndex('time', 'KEY'));
+               $buildstable->addChild(new DBIndex('`id`', 'PRIMARY KEY'));
+               $buildstable->addChild(new DBIndex('`time`', 'KEY'));
+               $buildstable->addChild(new DBIndex('`svn_version`', 'KEY'));
                $this->format->addChild($buildstable);
 
                $errortable = new DBTable('test_errors', 'InnoDB');
@@ -333,10 +334,12 @@
                $errortable->addChild(new DBField('before_id', 'INT NOT 
NULL'));
                $errortable->addChild(new DBField('last_id', 'INT NOT NULL'));
                $errortable->addChild(new DBField('error_type', 'VARCHAR(10) 
NOT NULL'));
-               $errortable->addChild(new DBField('file', 'VARCHAR(255) NOT 
NULL'));
+               $errortable->addChild(new DBField('file', 'VARCHAR(64) NOT 
NULL'));
                $errortable->addChild(new DBField('line', 'INT NOT NULL'));
                $errortable->addChild(new DBField('error_msg', 'BLOB NOT 
NULL'));
-               $errortable->addChild(new DBIndex('id', 'PRIMARY KEY'));
+               $errortable->addChild(new DBIndex('`id`', 'PRIMARY KEY'));
+//             $errortable->addChild(new DBIndex('`error_type`', 'KEY')); // 
posible key alternative for next one
+               $errortable->addChild(new DBIndex('`error_type`,`file`', 
'KEY', 'error_type_and_file'));
                $errortable->addChild(new 
DBForeignKey('test_errors_before_id_key','`before_id`', '`builds` (`id`)'));
                $errortable->addChild(new 
DBForeignKey('test_errors_last_id_key','`last_id`', '`builds` (`id`)'));
                $this->format->addChild($errortable);
@@ -351,7 +354,7 @@
                $resulttable->addChild(new DBField('test_cases_failed', 'INT 
NOT NULL'));
                $resulttable->addChild(new DBField('test_cases_skipped', 'INT 
NOT NULL'));
                $resulttable->addChild(new DBField('test_cases_aborted', 'INT 
NOT NULL'));
-               $resulttable->addChild(new DBIndex('id', 'PRIMARY KEY'));
+               $resulttable->addChild(new DBIndex('`id`', 'PRIMARY KEY'));
                $resulttable->addChild(new 
DBForeignKey('test_results_build_id_key', '`build_id`', '`builds` (`id`)'));
                $this->format->addChild($resulttable);
 

Added: branches/resources/tests.wesnoth.org/include/Paginate.php
URL: 
http://svn.gna.org/viewcvs/wesnoth/branches/resources/tests.wesnoth.org/include/Paginate.php?rev=28574&view=auto
==============================================================================
--- branches/resources/tests.wesnoth.org/include/Paginate.php (added)
+++ branches/resources/tests.wesnoth.org/include/Paginate.php Thu Aug 14 
07:38:56 2008
@@ -1,0 +1,71 @@
+<?php
+/*
+   Copyright (C) 2008 by Pauli Nieminen <paniemin@xxxxxxxxx>
+   Part of the Battle for Wesnoth Project http://www.wesnoth.org/
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License version 2
+   or at your option any later version.
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY.
+
+   See the COPYING file for more details.
+*/
+
+
+class Paginate {
+       private $link;
+       private $page;
+       private $number_of_pages;
+       private $number_of_visible_pages;
+
+       public function __construct($link, $page, $number_of_pages, 
$number_of_visible_pages)
+       {
+               $this->link = $link;
+               $this->page = $page;
+               $this->number_of_pages = $number_of_pages;
+               $this->number_of_visible_pages = $number_of_visible_pages;;
+       }
+
+       public function make()
+       {
+               
+               if ($this->page < 0)
+                       $this->page = 1;
+               if ($this->page > $this->number_of_pages)
+                       $this->page = $this->number_of_pages;
+               
+
+               $this->number_of_visible_pages = 5;
+               // Add one to visible if we are in begin or end
+               $visible_add = 0;
+               // Selected page should be in middle if possible
+               // Prefer to select page that has higher number than current
+               $start = $this->page - 
floor(($this->number_of_visible_pages-1)/2);
+               if ($start <= 1)
+               {
+                       $start = 1;
+                       $visible_add = 1;
+               }
+               $last = $start + $this->number_of_visible_pages + 
$visible_add;
+               // add one because smarty select loops untill the last but 
doesn't include it inside loop
+               if ($last >= $this->number_of_pages +1)
+               {
+                       $last = $this->number_of_pages + 1;
+                       $start = $last - $this->number_of_visible_pages - 1;
+                       if ($start < 1)
+                               $start = 1;
+               }
+               $ret = array();
+               $ret['link'] = $this->link;
+               $ret['page'] = $this->page;
+               $ret['first_page'] = $start; 
+               $ret['last_page'] = $last; 
+               $ret['number_of_pages'] = $this->number_of_pages;
+               $ret['visible'] = $last - $start; 
+
+               return $ret;
+       
+       }
+}
+?>

Propchange: branches/resources/tests.wesnoth.org/include/Paginate.php
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: branches/resources/tests.wesnoth.org/include/TestResult.php
URL: 
http://svn.gna.org/viewcvs/wesnoth/branches/resources/tests.wesnoth.org/include/TestResult.php?rev=28574&r1=28573&r2=28574&view=diff
==============================================================================
--- branches/resources/tests.wesnoth.org/include/TestResult.php (original)
+++ branches/resources/tests.wesnoth.org/include/TestResult.php Thu Aug 14 
07:38:56 2008
@@ -44,6 +44,8 @@
                        } else {
                                $this->fetch('WHERE build_id = ?', 
array($data));
                        }
+               } else {
+                       $this->reset();
                }
        }
 
@@ -57,6 +59,51 @@
                } else {
                        $this->reset();
                }
+       }
+
+       private static function multiFetch($where, $params = array())
+       {
+               global $db;
+               $result = $db->Execute('SELECT * FROM test_results '
+                       . $where, $params);
+               $ret = array();
+               while (!$result->EOF())
+               {
+                       $obj = new TestResult();
+                       $obj->init($result->fields);
+                       $ret[] = $obj;
+                       $result->moveNext();
+               } 
+               return $ret;
+       }
+
+
+       public static function fetchResultsForbuilds(&$builds)
+       {
+               $id_finder = array();
+               $id_list = array();
+               foreach($builds as $index => $build)
+               {
+                       $id_list[] = $build->getId();
+                       $id_finder[$build->getId()] = $index;
+               }
+               $results = self::multiFetch('WHERE build_id IN 
('.implode($id_list,',').')');
+
+               foreach($results as $result)
+               {
+                       
$builds[$id_finder[$result->getBuildId()]]->setResult($result);
+                       unset($id_finder[$result->getBuildId()]);
+               }
+               $empty_result = new TestResult();
+               foreach($id_finder as $index)
+               {
+                       $builds[$index]->setResult($empty_result);
+               }
+       }
+
+       public function getBuildId()
+       {
+               return $this->build_id;
        }
 
        private function init($values)

Modified: 
branches/resources/tests.wesnoth.org/smarty_workdir/templates/footer.tpl
URL: 
http://svn.gna.org/viewcvs/wesnoth/branches/resources/tests.wesnoth.org/smarty_workdir/templates/footer.tpl?rev=28574&r1=28573&r2=28574&view=diff
==============================================================================
--- branches/resources/tests.wesnoth.org/smarty_workdir/templates/footer.tpl 
(original)
+++ branches/resources/tests.wesnoth.org/smarty_workdir/templates/footer.tpl 
Thu Aug 14 07:38:56 2008
@@ -13,14 +13,14 @@
 </div>
 
 </div> <!-- global -->
-
+<!--
 <script type="text/javascript">
 _uacct = "UA-1872754-3";
 </script>
 <script type="text/javascript">
 urchinTracker();
 </script>
-
+-->
 </body>
 </html>
 {/strip}




Related Messages


Powered by MHonArc, Updated Thu Aug 14 11:21:42 2008