From 65f34c3a25631fa8ba75afe6e6e99f4315254394 Mon Sep 17 00:00:00 2001 From: Aaron Date: Mon, 27 Aug 2012 13:42:31 -0700 Subject: [PATCH] [FileJournal] Made getMasterDB() reuse the DB handle. * Also made use of autocommit mode while at it. Change-Id: I460e483d0103de70d505fe00dc9c67e33effde0c --- .../filebackend/filejournal/DBFileJournal.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/includes/filebackend/filejournal/DBFileJournal.php b/includes/filebackend/filejournal/DBFileJournal.php index 8fa4c6f0b5..f6268c258f 100644 --- a/includes/filebackend/filejournal/DBFileJournal.php +++ b/includes/filebackend/filejournal/DBFileJournal.php @@ -27,6 +27,9 @@ * @since 1.20 */ class DBFileJournal extends FileJournal { + /** @var DatabaseBase */ + protected $dbw; + protected $wiki = false; // string; wiki DB name /** @@ -71,9 +74,7 @@ class DBFileJournal extends FileJournal { } try { - $dbw->begin(); $dbw->insert( 'filejournal', $data, __METHOD__ ); - $dbw->commit(); } catch ( DBError $e ) { $status->fatal( 'filejournal-fail-dbquery', $this->backend ); return $status; @@ -125,12 +126,10 @@ class DBFileJournal extends FileJournal { $dbw = $this->getMasterDB(); $dbCutoff = $dbw->timestamp( time() - 86400 * $this->ttlDays ); - $dbw->begin(); $dbw->delete( 'filejournal', array( 'fj_timestamp < ' . $dbw->addQuotes( $dbCutoff ) ), __METHOD__ ); - $dbw->commit(); return $status; } @@ -142,7 +141,12 @@ class DBFileJournal extends FileJournal { * @throws DBError */ protected function getMasterDB() { - $lb = wfGetLBFactory()->newMainLB(); - return $lb->getConnection( DB_MASTER, array(), $this->wiki ); + if ( !$this->dbw ) { + // Get a separate connection in autocommit mode + $lb = wfGetLBFactory()->newMainLB(); + $this->dbw = $lb->getConnection( DB_MASTER, array(), $this->wiki ); + $this->dbw->clearFlag( DBO_TRX ); + } + return $this->dbw; } } -- 2.20.1