rdbms: remove DatabaseSqlite::checkForEnabledSearch() in favor of explicit queries
authorAaron Schulz <aschulz@wikimedia.org>
Thu, 8 Aug 2019 01:45:47 +0000 (18:45 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Thu, 8 Aug 2019 01:47:36 +0000 (18:47 -0700)
Change-Id: I0f13b9f054d7732f0e9694ec75c415f91a36ede9

includes/installer/SqliteInstaller.php
includes/libs/rdbms/database/DatabaseSqlite.php
includes/search/SearchSqlite.php

index cf91ccd..7c39ded 100644 (file)
@@ -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" );
index 97c4c9f..b1521dc 100644 (file)
@@ -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
index 9375ef2..84e6edd 100644 (file)
@@ -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 );
        }
 
        /**