Load previous tags in ChangeTags::addTags() from DB_MASTER
authorLiangent <liangent@gmail.com>
Thu, 5 Jun 2014 13:00:52 +0000 (13:00 +0000)
committerLiangent <liangent@gmail.com>
Thu, 5 Jun 2014 18:24:24 +0000 (18:24 +0000)
This fixes a bug in mobile [1] that the tag added by MobileApp gets
overwritten by MobileFrontend, where both use ChangeTags::addTags(),
and MobileFrontend is registered (thus called) after MobileApp.

[1] http://lists.wikimedia.org/pipermail/mobile-l/2014-June/007260.html

Change-Id: Ie47649ef45f9eebdfeae73a0698ea5d21b150b56

includes/ChangeTags.php

index d3dd51a..7e19164 100644 (file)
@@ -146,7 +146,10 @@ class ChangeTags {
                );
 
                ## Update the summary row.
-               $prevTags = $dbr->selectField( 'tag_summary', 'ts_tags', $tsConds, __METHOD__ );
+               $dbw = wfGetDB( DB_MASTER );
+               // $prevTags can be out of date on slaves, especially when addTags is called consecutively,
+               // causing loss of tags added recently in tag_summary table.
+               $prevTags = $dbw->selectField( 'tag_summary', 'ts_tags', $tsConds, __METHOD__ );
                $prevTags = $prevTags ? $prevTags : '';
                $prevTags = array_filter( explode( ',', $prevTags ) );
                $newTags = array_unique( array_merge( $prevTags, $tags ) );
@@ -158,7 +161,6 @@ class ChangeTags {
                        return false;
                }
 
-               $dbw = wfGetDB( DB_MASTER );
                $dbw->replace(
                        'tag_summary',
                        array( 'ts_rev_id', 'ts_rc_id', 'ts_log_id' ),