From 2eb5bdbac6b7de04679e16fd6c9d464e42e8a5d1 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Wed, 7 Aug 2019 18:45:47 -0700 Subject: [PATCH] rdbms: remove DatabaseSqlite::checkForEnabledSearch() in favor of explicit queries Change-Id: I0f13b9f054d7732f0e9694ec75c415f91a36ede9 --- includes/installer/SqliteInstaller.php | 9 +++++++- .../libs/rdbms/database/DatabaseSqlite.php | 22 ------------------- includes/search/SearchSqlite.php | 18 +++++++-------- 3 files changed, 17 insertions(+), 32 deletions(-) diff --git a/includes/installer/SqliteInstaller.php b/includes/installer/SqliteInstaller.php index cf91ccd9fc..7c39dedae4 100644 --- a/includes/installer/SqliteInstaller.php +++ b/includes/installer/SqliteInstaller.php @@ -356,7 +356,14 @@ EOT; global $IP; $module = DatabaseSqlite::getFulltextSearchModule(); - $fts3tTable = $this->db->checkForEnabledSearch(); + $searchIndexSql = (string)$this->db->selectField( + $this->db->addIdentifierQuotes( 'sqlite_master' ), + 'sql', + [ 'tbl_name' => $this->db->tableName( 'searchindex', 'raw' ) ], + __METHOD__ + ); + $fts3tTable = ( stristr( $searchIndexSql, 'fts' ) !== false ); + if ( $fts3tTable && !$module ) { $status->warning( 'config-sqlite-fts3-downgrade' ); $this->db->sourceFile( "$IP/maintenance/sqlite/archives/searchindex-no-fts.sql" ); diff --git a/includes/libs/rdbms/database/DatabaseSqlite.php b/includes/libs/rdbms/database/DatabaseSqlite.php index 97c4c9f235..b1521dca2f 100644 --- a/includes/libs/rdbms/database/DatabaseSqlite.php +++ b/includes/libs/rdbms/database/DatabaseSqlite.php @@ -269,28 +269,6 @@ class DatabaseSqlite extends Database { return preg_match( '/^(:memory:$|file:(:memory:|[^?]+\?mode=memory(&|$)))/', $path ); } - /** - * Check if the searchindext table is FTS enabled. - * @return bool False if not enabled. - */ - public function checkForEnabledSearch() { - if ( self::$fulltextEnabled === null ) { - self::$fulltextEnabled = false; - $table = $this->tableName( 'searchindex' ); - $res = $this->query( - "SELECT sql FROM sqlite_master WHERE tbl_name = '$table'", - __METHOD__, - self::QUERY_IGNORE_DBO_TRX - ); - if ( $res ) { - $row = $res->fetchRow(); - self::$fulltextEnabled = stristr( $row['sql'], 'fts' ) !== false; - } - } - - return self::$fulltextEnabled; - } - /** * Returns version of currently supported SQLite fulltext search module or false if none present. * @return string diff --git a/includes/search/SearchSqlite.php b/includes/search/SearchSqlite.php index 9375ef2d32..84e6edd9ee 100644 --- a/includes/search/SearchSqlite.php +++ b/includes/search/SearchSqlite.php @@ -22,7 +22,6 @@ */ use MediaWiki\MediaWikiServices; -use Wikimedia\Rdbms\DatabaseSqlite; /** * Search engine hook for SQLite @@ -34,14 +33,15 @@ class SearchSqlite extends SearchDatabase { * @return bool */ private function fulltextSearchSupported() { - // Avoid getConnectionRef() in order to get DatabaseSqlite specifically - /** @var DatabaseSqlite $dbr */ - $dbr = $this->lb->getConnection( DB_REPLICA ); - try { - return $dbr->checkForEnabledSearch(); - } finally { - $this->lb->reuseConnection( $dbr ); - } + $dbr = $this->lb->getMaintenanceConnectionRef( DB_REPLICA ); + $sql = (string)$dbr->selectField( + $dbr->addIdentifierQuotes( 'sqlite_master' ), + 'sql', + [ 'tbl_name' => $dbr->tableName( 'searchindex', 'raw' ) ], + __METHOD__ + ); + + return ( stristr( $sql, 'fts' ) !== false ); } /** -- 2.20.1