Deprecate ORMTable::getFieldPrefix
authorThiemo Mättig <thiemo.maettig@wikimedia.de>
Mon, 6 Oct 2014 16:04:40 +0000 (18:04 +0200)
committerThiemo Mättig <thiemo.maettig@wikimedia.de>
Tue, 14 Oct 2014 14:14:17 +0000 (16:14 +0200)
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
tests/phpunit/includes/db/ORMTableTest.php
tests/phpunit/includes/db/TestORMRowTest.php

index 24fa68c..9f3f8d2 100644 (file)
@@ -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 ) );
        }
 
        /**
index 7171ee5..f0c829c 100644 (file)
@@ -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_';
-       }
 }
index c9459c9..ca31cf9 100644 (file)
@@ -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_';
-       }
 }