jenkins-bot has submitted this change and it was merged.
Change subject: Move all TTMServer updates to the JobQueue
......................................................................
Move all TTMServer updates to the JobQueue
Slight speed-up to translation saves and deletes as updates
are now done via JobQueue. But more importantly failures
will now be caught by JobQueue rather than breaking
saves and deletes.
Remove return true from hooks per conventions.
Remove my copyright years per conventions (too lazy to update).
Bug: T132254
Change-Id: Ie6f1bfd5ba8224ef5642ac6c04c22a121d442f5b
---
M ttmserver/TTMServer.php
M ttmserver/TTMServerMessageUpdateJob.php
2 files changed, 44 insertions(+), 17 deletions(-)
Approvals:
DCausse: Looks good to me, approved
jenkins-bot: Verified
diff --git a/ttmserver/TTMServer.php b/ttmserver/TTMServer.php
index 5033505..58a970e 100644
--- a/ttmserver/TTMServer.php
+++ b/ttmserver/TTMServer.php
@@ -4,7 +4,6 @@
*
* @file
* @author Niklas Laxström
- * @copyright Copyright © 2012-2013, Niklas Laxström
* @license GPL-2.0+
* @defgroup TTMServer The Translate extension translation memory interface
*/
@@ -127,28 +126,23 @@
/// Hook: ArticleDeleteComplete
public static function onDelete( WikiPage $wikipage ) {
$handle = new MessageHandle( $wikipage->getTitle() );
- TTMServer::primary()->update( $handle, null );
-
- return true;
+ $job = TTMServerMessageUpdateJob::newJob( $handle, 'delete' );
+ JobQueueGroup::singleton()->push( $job );
}
/// Called from TranslateEditAddons::onSave
public static function onChange( MessageHandle $handle, $text, $fuzzy )
{
- if ( $fuzzy ) {
- $text = null;
- }
- TTMServer::primary()->update( $handle, $text );
+ $job = TTMServerMessageUpdateJob::newJob( $handle, 'refresh' );
+ JobQueueGroup::singleton()->push( $job );
}
public static function onGroupChange( MessageHandle $handle, $old, $new
) {
if ( $old === array() ) {
// Don't bother for newly added messages
- return true;
+ return;
}
- $job = TTMServerMessageUpdateJob::newJob( $handle );
+ $job = TTMServerMessageUpdateJob::newJob( $handle, 'rebuild' );
JobQueueGroup::singleton()->push( $job );
-
- return true;
}
}
diff --git a/ttmserver/TTMServerMessageUpdateJob.php
b/ttmserver/TTMServerMessageUpdateJob.php
index 9f10e73..d449024 100644
--- a/ttmserver/TTMServerMessageUpdateJob.php
+++ b/ttmserver/TTMServerMessageUpdateJob.php
@@ -4,7 +4,6 @@
*
* @file
* @author Niklas Laxström
- * @copyright Copyright © 2012-2013, Niklas Laxström
* @license GPL-2.0+
*/
@@ -18,8 +17,8 @@
* @param MessageHandle $handle
* @return TTMServerMessageUpdateJob
*/
- public static function newJob( MessageHandle $handle ) {
- $job = new self( $handle->getTitle() );
+ public static function newJob( MessageHandle $handle, $command ) {
+ $job = new self( $handle->getTitle(), array( 'command' =>
$command ) );
return $job;
}
@@ -38,13 +37,47 @@
*/
public function run() {
$handle = new MessageHandle( $this->title );
+
+ // For old jobs before this param was added
+ $command = isset( $this->params['command'] ) ?
$this->params['command'] : 'rebuild';
+
+ // JobQueue will catch exceptions and retry the job few times,
+ // after which it will be abandoned.
+ if ( $command === 'delete' ) {
+ $this->updateItem( $handle, null, false );
+ } elseif ( $command === 'rebuild' ) {
+ $this->updateMessage( $handle );
+ } elseif ( $command === 'refresh' ) {
+ $this->updateTranslation( $handle );
+ }
+
+ return true;
+ }
+
+ private function updateMessage( MessageHandle $handle ) {
+ // Base page update, e.g. group change. Update everything.
$translations = ApiQueryMessageTranslations::getTranslations(
$handle );
foreach ( $translations as $page => $data ) {
$tTitle = Title::makeTitle(
$this->title->getNamespace(), $page );
$tHandle = new MessageHandle( $tTitle );
- TTMServer::onChange( $tHandle, $data[0],
$tHandle->isFuzzy() );
+ $this->updateItem( $tHandle, $data[0],
$tHandle->isFuzzy() );
}
+ }
- return true;
+ private function updateTranslation( MessageHandle $handle ) {
+ // Update only this translation
+ $translation = TranslateUtils::getMessageContent(
+ $handle->getKey(),
+ $handle->getCode(),
+ $handle->getTitle()->getNamespace()
+ );
+ $this->updateItem( $handle, $translation, $handle->isFuzzy() );
+ }
+
+ private function updateItem( MessageHandle $handle, $text, $fuzzy ) {
+ if ( $fuzzy ) {
+ $text = null;
+ }
+ TTMServer::primary()->update( $handle, $text );
}
}
--
To view, visit https://gerrit.wikimedia.org/r/282651
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ie6f1bfd5ba8224ef5642ac6c04c22a121d442f5b
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Translate
Gerrit-Branch: master
Gerrit-Owner: Nikerabbit <[email protected]>
Gerrit-Reviewer: DCausse <[email protected]>
Gerrit-Reviewer: Gehel <[email protected]>
Gerrit-Reviewer: Nikerabbit <[email protected]>
Gerrit-Reviewer: Santhosh <[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