From 704583440ed27e1e0b7f463112233816cdade8a1 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Tue, 14 Jul 2015 12:11:32 -0700 Subject: [PATCH] Added DBAccessObjectUtils class to avoid duplication * WikiPage is the first caller to use this instead of DIY * This can be used elsewhere to keep callers uniform Change-Id: Ia6371eaa185d70d1431271b2c6c955523cd424e8 --- autoload.php | 1 + includes/dao/DBAccessObjectUtils.php | 59 ++++++++++++++++++++++++++++ includes/page/WikiPage.php | 14 +++---- 3 files changed, 67 insertions(+), 7 deletions(-) create mode 100644 includes/dao/DBAccessObjectUtils.php diff --git a/autoload.php b/autoload.php index 6444e3efa8..2a096f460b 100644 --- a/autoload.php +++ b/autoload.php @@ -279,6 +279,7 @@ $wgAutoloadLocalClasses = array( 'CurlHttpRequest' => __DIR__ . '/includes/HttpFunctions.php', 'DBAccessBase' => __DIR__ . '/includes/dao/DBAccessBase.php', 'DBAccessError' => __DIR__ . '/includes/db/LBFactory.php', + 'DBAccessObjectUtils' => __DIR__ . '/includes/dao/DBAccessObjectUtils.php', 'DBConnRef' => __DIR__ . '/includes/db/DBConnRef.php', 'DBConnectionError' => __DIR__ . '/includes/db/DatabaseError.php', 'DBError' => __DIR__ . '/includes/db/DatabaseError.php', diff --git a/includes/dao/DBAccessObjectUtils.php b/includes/dao/DBAccessObjectUtils.php new file mode 100644 index 0000000000..58f991fc10 --- /dev/null +++ b/includes/dao/DBAccessObjectUtils.php @@ -0,0 +1,59 @@ +pageDataFromTitle( wfGetDB( DB_MASTER ), $this->mTitle, array( 'FOR UPDATE' ) ); - } elseif ( $from === self::READ_LATEST ) { - $data = $this->pageDataFromTitle( wfGetDB( DB_MASTER ), $this->mTitle ); - } elseif ( $from === self::READ_NORMAL ) { - $data = $this->pageDataFromTitle( wfGetDB( DB_SLAVE ), $this->mTitle ); + if ( is_int( $from ) ) { + list( $index, $opts ) = DBAccessObjectUtils::getDBOptions( $from ); + $data = $this->pageDataFromTitle( wfGetDB( $index ), $this->mTitle, $opts ); + if ( !$data + && $index == DB_SLAVE && wfGetLB()->getServerCount() > 1 && wfGetLB()->hasOrMadeRecentMasterChanges() ) { $from = self::READ_LATEST; - $data = $this->pageDataFromTitle( wfGetDB( DB_MASTER ), $this->mTitle ); + list( $index, $opts ) = DBAccessObjectUtils::getDBOptions( $from ); + $data = $this->pageDataFromTitle( wfGetDB( $index ), $this->mTitle, $opts ); } } else { // No idea from where the caller got this data, assume slave database. -- 2.20.1