Physikerwelt has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/104952


Change subject: use transactions for faster import
......................................................................

use transactions for faster import

Change-Id: Ibd6dd2e318c2b18bb60e10b845076ee33d2dbc04
---
M maintenance/ExportMathTable.php
M maintenance/IndexBase.php
2 files changed, 23 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MathSearch 
refs/changes/52/104952/1

diff --git a/maintenance/ExportMathTable.php b/maintenance/ExportMathTable.php
index 7338740..a5c7f30 100644
--- a/maintenance/ExportMathTable.php
+++ b/maintenance/ExportMathTable.php
@@ -30,6 +30,7 @@
 class ExportMathTable extends IndexBase {
        private $db2Pass;
        private $statment;
+       private $dbh;
        /**
         *
         */
@@ -52,11 +53,27 @@
                $out .= ','. $row->mathindex_anchor.'';
                $out .= ',"'.str_replace(array('"',"\n"),array('"',' '), 
$mo->getMathml()).'"';
                if( $this->db2Pass ) {
-                       
$this->statment->execute(array($mo->getMd5(),$mo->getTex(),$row->mathindex_page_id,$row->mathindex_anchor,$mo->getMathml()));
+                       try { 
+                               
$this->statment->execute(array($mo->getMd5(),$mo->getTex(),$row->mathindex_page_id,$row->mathindex_anchor,$mo->getMathml()));
+                       } catch (Exception $e) {
+                         echo($e->getMessage());
+                       }
+
 }
                return $out."\n";
 
        }
+protected function wFile( $fn, $min, $inc ) {
+       if( $this->db2Pass ) {
+               try{
+               $this->dbh->commit();
+               } catch (Exception $e) {
+                         echo($e->getMessage());
+               }
+               $this->dbh->beginTransaction();
+       }
+       return parent::wFile( $fn, $min, $inc );
+}
 
        /**
         *
@@ -65,7 +82,7 @@
                $this->db2Pass = $this->getOption( 'passw',false );
                if ( $this->db2Pass ){
                        try { 
-                               $connection = new PDO("ibm:MATH", "db2inst1", 
$this->db2Pass, array(
+                               $this->dbh = new PDO("ibm:MATH", "db2inst1", 
$this->db2Pass, array(
                                        PDO::ATTR_PERSISTENT => TRUE, 
                                        PDO::ATTR_ERRMODE => 
PDO::ERRMODE_EXCEPTION)
                                ); 
@@ -73,9 +90,10 @@
                          echo($e->getMessage());
                        }
                        if ( $this->getOption('truncate' , false ) ){
-                                $connection->query('TRUNCATE TABLE 
"wiki"."math" IMMEDIATE');
+                                $this->dbh->query('TRUNCATE TABLE 
"wiki"."math" IMMEDIATE');
                        }
-                       $this->statment = $connection->prepare('insert into 
"wiki"."math" ("math_md5", "math_tex", "mathindex_pageid", "mathindex_anchord", 
"math_mathml") values(?, ?, ?, ?, ?)');
+                       $this->dbh->beginTransaction();
+                       $this->statment = $this->dbh->prepare('insert into 
"wiki"."math" ("math_md5", "math_tex", "mathindex_pageid", "mathindex_anchord", 
"math_mathml") values(?, ?, ?, ?, ?)');
                        
                }
                parent::execute();
diff --git a/maintenance/IndexBase.php b/maintenance/IndexBase.php
index 5edfe95..68d919d 100644
--- a/maintenance/IndexBase.php
+++ b/maintenance/IndexBase.php
@@ -53,7 +53,7 @@
         * @param unknown $inc
         * @return boolean
         */
-       private function wFile( $fn, $min, $inc ) {
+       protected function wFile( $fn, $min, $inc ) {
                $out = $this->getHead();
                $max = min( $min + $inc, $this->res->numRows() -1 );
                for ( $i = $min; $i < $max; $i++ ) {

-- 
To view, visit https://gerrit.wikimedia.org/r/104952
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibd6dd2e318c2b18bb60e10b845076ee33d2dbc04
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MathSearch
Gerrit-Branch: master
Gerrit-Owner: Physikerwelt <w...@physikerwelt.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to