From db257c7de11da2771a9f61733f21a42c98cf2a97 Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Mon, 1 Nov 2010 18:40:08 +0100 Subject: add CommonTable->optimize() method and call it during refresh --- class/CommonTable.php | 17 ++++++++++++++++- class/Parser.php | 2 +- class/TableIterator.php | 6 +++++- refresh.php | 24 ++++++++++++++++++++---- testdb.php | 3 +++ 5 files changed, 45 insertions(+), 7 deletions(-) diff --git a/class/CommonTable.php b/class/CommonTable.php index b7cc93e..365ef19 100644 --- a/class/CommonTable.php +++ b/class/CommonTable.php @@ -84,7 +84,9 @@ abstract class CommonTable $res = $this->db->exec($sql); if ($res===false) { $err = $this->db->errorInfo(); - throw new Exception("\nSQL: $sql\nERROR: ".$err[2]."\nCODE:"); + throw new Exception( + "\nSQL: $sql\nERROR: " . $err[2] . "\nCODE:" . $err[0] + ); } return $res; } @@ -315,6 +317,19 @@ abstract class CommonTable return $this->exec('TRUNCATE `'.$this->table.'`'); } + /** + * Optimize the table + */ + public function optimize() + { + $res = array(); + foreach ($this->request('OPTIMIZE TABLE `'.$this->table.'`') as $row) { + $res[] = $row; + } + return $res; + } + + /** * Get the number of rows in the table */ diff --git a/class/Parser.php b/class/Parser.php index ef4a751..79d1282 100644 --- a/class/Parser.php +++ b/class/Parser.php @@ -39,7 +39,7 @@ class Parser /** * Display a message */ - static private function log($msg) + static public function log($msg) { echo date("r : ") . $msg ."\n"; } diff --git a/class/TableIterator.php b/class/TableIterator.php index dfae859..6e44c18 100644 --- a/class/TableIterator.php +++ b/class/TableIterator.php @@ -230,7 +230,11 @@ class TableIterator implements Iterator if ($this->_res && $this->_pos<0) { if (!$this->_res->execute()) { $err = $this->_res->errorInfo(); - throw new Exception($err[2]); + throw new Exception( + "\nSQL: " . $this->_sql . + "\nERROR: " . $err[2] . + "\nCODE:" . $err[0] + ); } } return $this->next(); diff --git a/refresh.php b/refresh.php index 6c7827b..6d934c5 100644 --- a/refresh.php +++ b/refresh.php @@ -49,8 +49,8 @@ require "include/main.php"; require "class/CommonTable.php"; if ($_SERVER['argc']>1 && in_array('help', $_SERVER['argv'])) { - echo "Options in: repo owner R pear pecl old\n"; - echo "Defaults: repo owner R pear pecl\n"; + echo "Options in: owner R pear pecl optimize repo old empty\n"; + echo "Defaults: owner R pear pecl optimize repo \n"; die("\n"); } @@ -62,6 +62,7 @@ try { // ------------------------------------------------------------------- echo date("r : ") . "Refreshing " . MYBASE . " database\n"; + $rpmtable = new TableRpm($db); if ($_SERVER['argc']==1 || in_array('repo', $_SERVER['argv'])) { if (in_array('empty', $_SERVER['argv'])) { @@ -72,7 +73,7 @@ try { $crit = array('active' => 1); } - Parser::readRpm(new TableRpm($db), new TableRpmRepo($db), $crit); + Parser::readRpm($rpmtable, new TableRpmRepo($db), $crit); } // ------------------------------------------------------------------- @@ -101,10 +102,25 @@ try { // ------------------------------------------------------------------- // Package Owners from pkgdb (thanks Smootherfrog) // ------------------------------------------------------------------- + $acltable = new TableAcls($db); if ($_SERVER['argc']==1 || in_array('owner', $_SERVER['argv'])) { $url = "https://admin.fedoraproject.org/pkgdb/lists/bugzilla?tg_format=plain"; - Parser::readAcls(new TableAcls($db), $url); + Parser::readAcls($acltable, $url); + } + + if ($_SERVER['argc']==1 || in_array('optimize', $_SERVER['argv'])) { + Parser::log("OPTIMIZE rpm table"); + $res = $rpmtable->optimize(); + Parser::log($res[0]['Msg_type'] . ' = ' . $res[0]['Msg_text']); + + Parser::log("OPTIMIZE upstream table"); + $res = $uptable->optimize(); + Parser::log($res[0]['Msg_type'] . ' = ' . $res[0]['Msg_text']); + + Parser::log("OPTIMIZE acls table"); + $res = $acltable->optimize(); + Parser::log($res[0]['Msg_type'] . ' = ' . $res[0]['Msg_text']); } } catch(PDOException $e) { diff --git a/testdb.php b/testdb.php index 2b60304..128561c 100644 --- a/testdb.php +++ b/testdb.php @@ -96,4 +96,7 @@ foreach($up->request(array('type'=>'test', 'ORDER'=>'name')) as $upstr) { $rpm = new TableRpm($db); $acl = new TableAcls($db); echo "Acls number : ".$acl->getCount()."\n"; +$res = $acl->optimize(); +echo "Acls optimization : ".$res[0]['Msg_type'].'='.$res[0]['Msg_text']."\n"; + ?> -- cgit