jenkins-bot has submitted this change and it was merged. Change subject: Defer translation page update edit after translation unit deletion to post current transaction ......................................................................
Defer translation page update edit after translation unit deletion to post current transaction Users can use tools which can mass delete (eg. Nuke) multiple translation units in one request. This means onDeleteTranslationUnit() will do many edits to a translation page (and do MessageGroupStats queries) many times if many translation units belonging to one translation page was deleted in one request. This is quite bad user experience and can also be slow for the user. To avoid this, we are now deferring the update to be done after the current transaction is committed so that we can use the text that is after all the units has been deleted. Additionally, we now use a queue-based system so that only one update is done for each translation page in order to avoid doing unnecessary stats updates, null edits and purges (and other secondary updates) to these pages. I'm not sure whether this will work in all cases where users can do multiple deletions in a single request but at least this works for Nuke which is what is used on Wikimedia for doing batch deletions in one request. This was suggested at https://meta.wikimedia.org/?oldid=15647503#Deleting_translations Change-Id: I2df5411fb51b6e45888fb7333855cf5a75732af9 --- M tag/PageTranslationHooks.php 1 file changed, 34 insertions(+), 8 deletions(-) Approvals: Nikerabbit: Checked; Looks good to me, approved jenkins-bot: Verified diff --git a/tag/PageTranslationHooks.php b/tag/PageTranslationHooks.php index 1c93456..f4128b7 100644 --- a/tag/PageTranslationHooks.php +++ b/tag/PageTranslationHooks.php @@ -981,17 +981,43 @@ return true; } + // There could be interfaces which may allow mass deletion (eg. Nuke). Since they could + // delete many units in one request, it may do several unnecessary edits and cause several + // other unnecessary updates to be done slowing down the user. To avoid that, we push this + // to a queue that is run after the current transaction is committed so that we can see the + // version that is after all the deletions has been done. This allows us to do just one edit + // per translation page after the current deletions has been done. This is sort of hackish + // but this is better user experience and is also more efficent. + static $queuedPages = array(); + $target = $group->getTitle(); $langCode = $handle->getCode(); - $id = $group->getId(); + $targetPage = $target->getSubpage( $langCode )->getPrefixedText(); - MessageGroupStats::clear( $handle ); - MessageGroupStats::forItem( $id, $langCode ); + if ( !isset( $queuedPages[ $targetPage ] ) ) { + $queuedPages[ $targetPage ] = true; - if ( $handle->isDoc() ) { - return true; + $dbw = wfGetDB( DB_MASTER ); + $dbw->onTransactionIdle( function () use ( $dbw, $queuedPages, $targetPage, + $target, $handle, $langCode, $user, $reason + ) { + // For atomicity + $dbw->setFlag( DBO_TRX ); + + $page = TranslatablePage::newFromTitle( $target ); + + MessageGroupStats::clear( $handle ); + MessageGroupStats::forItem( $page->getMessageGroupId(), $langCode ); + + if ( !$handle->isDoc() ) { + // Assume that $user and $reason for the first deletion is the same for all + self::updateTranslationPage( $page, $langCode, $user, 0, $reason ); + } + + // If a unit was deleted after the edit here is done, this allows us + // to add the page back to the queue again and so we can make another + // edit here with the latest changes. + unset( $queuedPages[ $targetPage ] ); + } ); } - - $page = TranslatablePage::newFromTitle( $group->getTitle() ); - self::updateTranslationPage( $page, $langCode, $user, 0, $reason ); } } -- To view, visit https://gerrit.wikimedia.org/r/290978 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I2df5411fb51b6e45888fb7333855cf5a75732af9 Gerrit-PatchSet: 3 Gerrit-Project: mediawiki/extensions/Translate Gerrit-Branch: master Gerrit-Owner: Glaisher <[email protected]> Gerrit-Reviewer: Glaisher <[email protected]> Gerrit-Reviewer: Nikerabbit <[email protected]> Gerrit-Reviewer: Siebrand <[email protected]> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
