Jjanes has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/153565

Change subject: PostgreSQL: Fix text search on moved pages
......................................................................

PostgreSQL: Fix text search on moved pages

When a page is updated under PostgreSQL, there is code to
de-index all but the most recent version of the page.  But
when a page is moved, it was accidentally de-indexing the
most recent version as well, because rev_text_id is not
incremented in that case.  A simple tweak to the SQL
fixes that.

I added code to the update script to find pages
previously corrupted by this problem and reindex them.
This code runs unconditionally because I cannot think
of robust way to know if the database was ever used
under a system which potentially suffered from this bug.

Bug: 66650
Change-Id: I52e1bbbd8592be5e7c7383c225e6b4c19bbe5b9e
---
M includes/installer/PostgresUpdater.php
M includes/search/SearchPostgres.php
2 files changed, 11 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/65/153565/1

diff --git a/includes/installer/PostgresUpdater.php 
b/includes/installer/PostgresUpdater.php
index 9e8ee94..22222a4 100644
--- a/includes/installer/PostgresUpdater.php
+++ b/includes/installer/PostgresUpdater.php
@@ -418,6 +418,8 @@
                        array( 'addPgField', 'pagelinks', 'pl_from_namespace', 
'INTEGER NOT NULL DEFAULT 0' ),
                        array( 'addPgField', 'templatelinks', 
'tl_from_namespace', 'INTEGER NOT NULL DEFAULT 0' ),
                        array( 'addPgField', 'imagelinks', 'il_from_namespace', 
'INTEGER NOT NULL DEFAULT 0' ),
+                       // bug 66650
+                       array( 'textvectorFix' ),
                );
        }
 
@@ -925,4 +927,12 @@
                        $this->applyPatch( 'patch-tsearch2funcs.sql', false, 
"Rewriting tsearch2 triggers" );
                }
        }
+
+       protected function textvectorFix() {
+               $this->output( "Restoring textvector field\n" );
+               $this->db->query(
+                       "UPDATE pagecontent SET 
textvector=to_tsvector(old_text) " .
+                       "WHERE textvector IS NULL AND old_id IN " .
+                       "(SELECT  max(rev_text_id) FROM revision GROUP BY 
rev_page)" );
+       }
 }
diff --git a/includes/search/SearchPostgres.php 
b/includes/search/SearchPostgres.php
index 914bc1c..bceb1ae 100644
--- a/includes/search/SearchPostgres.php
+++ b/includes/search/SearchPostgres.php
@@ -185,7 +185,7 @@
        function update( $pageid, $title, $text ) {
                ## We don't want to index older revisions
                $sql = "UPDATE pagecontent SET textvector = NULL WHERE 
textvector IS NOT NULL and old_id IN " .
-                               "(SELECT rev_text_id FROM revision WHERE 
rev_page = " . intval( $pageid ) .
+                               "(SELECT DISTINCT rev_text_id FROM revision 
WHERE rev_page = " . intval( $pageid ) .
                                " ORDER BY rev_text_id DESC OFFSET 1)";
                $this->db->query( $sql );
                return true;

-- 
To view, visit https://gerrit.wikimedia.org/r/153565
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I52e1bbbd8592be5e7c7383c225e6b4c19bbe5b9e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Jjanes <jeff.ja...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to