From 9bd9c31c737522efd6f2530df883d8c144177380 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Thiemo=20M=C3=A4ttig?= Date: Mon, 6 Oct 2014 18:04:40 +0200 Subject: [PATCH] Deprecate ORMTable::getFieldPrefix Internal calls to this method show up in my XDebug profiling as the second most called method (after array_key_exists). Called 10000 times. Sure, it's very cheap and clearly not a bottleneck. But just not necesarry to have a method for that. The benefit of having a method is to have a dynamic prefix that can change depending on other things in an object. But I think this is not a good idea for a prefix. Since this is protected it is part of the contract of this class. I already cleaned known subclasses. Should be @deprecated for some time and can be removed later. Change-Id: I46a0d7e072d0a69e9aef5f77e92044b62e3d0ce7 --- includes/db/ORMTable.php | 5 +++-- tests/phpunit/includes/db/ORMTableTest.php | 13 ++++--------- tests/phpunit/includes/db/TestORMRowTest.php | 15 ++++----------- 3 files changed, 11 insertions(+), 22 deletions(-) diff --git a/includes/db/ORMTable.php b/includes/db/ORMTable.php index 24fa68c504..9f3f8d24fe 100644 --- a/includes/db/ORMTable.php +++ b/includes/db/ORMTable.php @@ -129,6 +129,7 @@ class ORMTable extends DBAccessBase implements IORMTable { * Gets the db field prefix. * * @since 1.20 + * @deprecated since 1.25, use the $this->fieldPrefix property instead * * @return string */ @@ -770,7 +771,7 @@ class ORMTable extends DBAccessBase implements IORMTable { * @return string */ public function getPrefixedField( $field ) { - return $this->getFieldPrefix() . $field; + return $this->fieldPrefix . $field; } /** @@ -796,7 +797,7 @@ class ORMTable extends DBAccessBase implements IORMTable { * @return string */ public function unprefixFieldName( $fieldName ) { - return substr( $fieldName, strlen( $this->getFieldPrefix() ) ); + return substr( $fieldName, strlen( $this->fieldPrefix ) ); } /** diff --git a/tests/phpunit/includes/db/ORMTableTest.php b/tests/phpunit/includes/db/ORMTableTest.php index 7171ee5913..f0c829c84b 100644 --- a/tests/phpunit/includes/db/ORMTableTest.php +++ b/tests/phpunit/includes/db/ORMTableTest.php @@ -99,6 +99,10 @@ class ORMTableTest extends MediaWikiTestCase { class PageORMTableForTesting extends ORMTable { + public function __construct() { + $this->fieldPrefix = 'page_'; + } + /** * @see ORMTable::getName * @@ -138,13 +142,4 @@ class PageORMTableForTesting extends ORMTable { 'title' => 'str', ); } - - /** - * @see ORMTable::getFieldPrefix - * - * @return string - */ - protected function getFieldPrefix() { - return 'page_'; - } } diff --git a/tests/phpunit/includes/db/TestORMRowTest.php b/tests/phpunit/includes/db/TestORMRowTest.php index c9459c9039..ca31cf94ee 100644 --- a/tests/phpunit/includes/db/TestORMRowTest.php +++ b/tests/phpunit/includes/db/TestORMRowTest.php @@ -150,6 +150,10 @@ class TestORMRow extends ORMRow { class TestORMTable extends ORMTable { + public function __construct() { + $this->fieldPrefix = 'test_'; + } + /** * Returns the name of the database table objects of this type are stored in. * @@ -204,15 +208,4 @@ class TestORMTable extends ORMTable { 'time' => 'str', // TS_MW ); } - - /** - * Gets the db field prefix. - * - * @since 1.20 - * - * @return string - */ - protected function getFieldPrefix() { - return 'test_'; - } } -- 2.20.1