Glaisher has uploaded a new change for review. https://gerrit.wikimedia.org/r/290978
Change subject: Defer translation page update edit after translation unit deletion to a separate transaction ...................................................................... Defer translation page update edit after translation unit deletion to a separate 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 a separate transaction after the main transaction 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, 23 insertions(+), 8 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Translate refs/changes/78/290978/1 diff --git a/tag/PageTranslationHooks.php b/tag/PageTranslationHooks.php index 1c93456..5a2c43b 100644 --- a/tag/PageTranslationHooks.php +++ b/tag/PageTranslationHooks.php @@ -981,17 +981,32 @@ 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 separate transaction so that we can see the + // version that is after all the deletions has been done and we so we can do just one + // edit per translatable 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 ( !in_array( $targetPage, $queuedPages ) ) { + $queuedPages[] = $targetPage; - if ( $handle->isDoc() ) { - return true; + $dbw = wfGetDB( DB_MASTER ); + $dbw->onTransactionIdle( function () use ( $target, $handle, $langCode, $user, $reason ) { + $page = TranslatablePage::newFromTitle( $target ); + + MessageGroupStats::clear( $handle ); + MessageGroupStats::forItem( $page->getMessageGroupId(), $langCode ); + + if ( !$handle->isDoc() ) { + self::updateTranslationPage( $page, $langCode, $user, 0, $reason ); + } + } ); } - - $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: newchange Gerrit-Change-Id: I2df5411fb51b6e45888fb7333855cf5a75732af9 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Translate Gerrit-Branch: master Gerrit-Owner: Glaisher <[email protected]> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
