Also make getLazyMasterHandle() protected.
Change-Id: Id6b48ff976a800052c22e90b572695ab3b8beb7e
/** @var IDatabase|null Lazy handle to the master DB this server replicates from */
private $lazyMasterHandle;
- /**
- * @since 1.22
- * @var string[] Process cache of VIEWs names in the database
- */
- protected $allViews = null;
-
/** @var float UNIX timestamp */
protected $lastPing = 0.0;
* @see setLazyMasterHandle()
* @since 1.27
*/
- public function getLazyMasterHandle() {
+ protected function getLazyMasterHandle() {
return $this->lazyMasterHandle;
}
throw new RuntimeException( __METHOD__ . ' is not implemented in descendant class' );
}
- /**
- * Reset the views process cache set by listViews()
- * @since 1.22
- */
- final public function clearViewsCache() {
- $this->allViews = null;
- }
-
public function listViews( $prefix = null, $fname = __METHOD__ ) {
throw new RuntimeException( __METHOD__ . ' is not implemented in descendant class' );
}
- /**
- * Differentiates between a TABLE and a VIEW
- *
- * @param string $name Name of the database-structure to test.
- * @throws RuntimeException
- * @return bool
- * @since 1.22
- */
- public function isView( $name ) {
- throw new RuntimeException( __METHOD__ . ' is not implemented in descendant class' );
- }
-
public function timestamp( $ts = 0 ) {
$t = new ConvertibleTimestamp( $ts );
// Let errors bubble up to avoid putting garbage in the DB
* @since 1.22
*/
public function listViews( $prefix = null, $fname = __METHOD__ ) {
+ // The name of the column containing the name of the VIEW
+ $propertyName = 'Tables_in_' . $this->mDBname;
- if ( !isset( $this->allViews ) ) {
-
- // The name of the column containing the name of the VIEW
- $propertyName = 'Tables_in_' . $this->mDBname;
-
- // Query for the VIEWS
- $result = $this->query( 'SHOW FULL TABLES WHERE TABLE_TYPE = "VIEW"' );
- $this->allViews = [];
- while ( ( $row = $this->fetchRow( $result ) ) !== false ) {
- array_push( $this->allViews, $row[$propertyName] );
- }
+ // Query for the VIEWS
+ $res = $this->query( 'SHOW FULL TABLES WHERE TABLE_TYPE = "VIEW"' );
+ $allViews = [];
+ foreach ( $res as $row ) {
+ array_push( $allViews, $row->$propertyName );
}
if ( is_null( $prefix ) || $prefix === '' ) {
- return $this->allViews;
+ return $allViews;
}
$filteredViews = [];
- foreach ( $this->allViews as $viewName ) {
+ foreach ( $allViews as $viewName ) {
// Does the name of this VIEW start with the table-prefix?
if ( strpos( $viewName, $prefix ) === 0 ) {
array_push( $filteredViews, $viewName );
/**
* Lists all the VIEWs in the database
*
- * For caching purposes the list of all views should be stored in
- * $this->allViews. The process cache can be cleared with clearViewsCache()
- *
* @param string $prefix Only show VIEWs with this prefix, eg. unit_test_
* @param string $fname Name of calling function
* @throws RuntimeException
*
* @return array
*/
- public static function listTables( $db ) {
+ public static function listTables( DatabaseBase $db ) {
$prefix = $db->tablePrefix();
$tables = $db->listTables( $prefix, __METHOD__ );
if ( $db->getType() === 'mysql' ) {
- # bug 43571: cannot clone VIEWs under MySQL
- $views = $db->listViews( $prefix, __METHOD__ );
- $tables = array_diff( $tables, $views );
+ static $viewListCache = null;
+ if ( $viewListCache === null ) {
+ $viewListCache = $db->listViews( null, __METHOD__ );
+ }
+ // T45571: cannot clone VIEWs under MySQL
+ $tables = array_diff( $tables, $viewListCache );
}
array_walk( $tables, [ __CLASS__, 'unprefixTable' ], $prefix );
$db->method( 'query' )
->with( $this->anything() )
- ->willReturn( null );
+ ->willReturn( new FakeResultWrapper( [
+ (object)[ 'Tables_in_' => 'view1' ],
+ (object)[ 'Tables_in_' => 'view2' ],
+ (object)[ 'Tables_in_' => 'myview' ]
+ ] ) );
- $db->method( 'fetchRow' )
- ->with( $this->anything() )
- ->will( $this->onConsecutiveCalls(
- [ 'Tables_in_' => 'view1' ],
- [ 'Tables_in_' => 'view2' ],
- [ 'Tables_in_' => 'myview' ],
- false # no more rows
- ) );
return $db;
}
/**
function testListviews() {
$db = $this->getMockForViews();
- // The first call populate an internal cache of views
- $this->assertEquals( [ 'view1', 'view2', 'myview' ],
- $db->listViews() );
$this->assertEquals( [ 'view1', 'view2', 'myview' ],
$db->listViews() );
$db->listViews( '' ) );
}
- /**
- * @covers DatabaseMysqlBase::isView
- * @dataProvider provideViewExistanceChecks
- */
- function testIsView( $isView, $viewName ) {
- $db = $this->getMockForViews();
-
- switch ( $isView ) {
- case true:
- $this->assertTrue( $db->isView( $viewName ),
- "$viewName should be considered a view" );
- break;
-
- case false:
- $this->assertFalse( $db->isView( $viewName ),
- "$viewName has not been defined as a view" );
- break;
- }
-
- }
-
- function provideViewExistanceChecks() {
- return [
- // format: whether it is a view, view name
- [ true, 'view1' ],
- [ true, 'view2' ],
- [ true, 'myview' ],
-
- [ false, 'user' ],
-
- [ false, 'view10' ],
- [ false, 'my' ],
- [ false, 'OH_MY_GOD' ], # they killed kenny!
- ];
- }
-
/**
* @dataProvider provideComparePositions
*/