[MediaWiki-commits] [Gerrit] Reduce the frequency of AbuseFilter Validations - change (mediawiki...ContentTranslation)
jenkins-bot has submitted this change and it was merged. Change subject: Reduce the frequency of AbuseFilter Validations .. Reduce the frequency of AbuseFilter Validations The frequence fragment validation need Restbase and eventually parsoid to do the validations. Validating in every autosave will not be smart as per recent observations in the increase in requests to Restbase. Following approach is attempted: 1. In translation units that are sent to cxsave API for saving have a boolean typed validate flag. If true, it will be validated, otherwise skipped 2. The translation storage module will be responsible for setting that flag true or false 3. Do not set that flag true for sections other than paragraphs and target title. 4. Set the validate flag true in every 10th autosave 5. Set the validate flag true if the section has a validation error Bug: T129314 Change-Id: I8660527a891b77e272e9af1d6d3b0bbe3ee5ebf2 --- M api/ApiContentTranslationSave.php M includes/TranslationUnit.php M modules/translation/ext.cx.translation.storage.js 3 files changed, 38 insertions(+), 3 deletions(-) Approvals: Nikerabbit: Checked; Looks good to me, approved jenkins-bot: Verified diff --git a/api/ApiContentTranslationSave.php b/api/ApiContentTranslationSave.php index 3f31a97..cf2a569 100644 --- a/api/ApiContentTranslationSave.php +++ b/api/ApiContentTranslationSave.php @@ -77,6 +77,9 @@ $checker = new AbuseFilterCheck( $this->getUser(), $title ); foreach ( $translationUnits as $translationUnit ) { + if ( !$translationUnit->getValidate() ) { + continue; + } $sectionId = $translationUnit->getSectionId(); if ( $sectionId === 'mwcx-source-title' ) { $validationResults[$sectionId] = @@ -190,7 +193,9 @@ // Content can be null in case translator clear the section. $tuData['content'] = null; } - + if ( !isset( $tuData['validate'] ) ) { + $tuData['validate'] = false; + } $tuData['translationId'] = $this->translation->getTranslationId(); $translationUnits[] = new TranslationUnit( $tuData ); } diff --git a/includes/TranslationUnit.php b/includes/TranslationUnit.php index 7a529b3..d2420c2 100644 --- a/includes/TranslationUnit.php +++ b/includes/TranslationUnit.php @@ -16,6 +16,7 @@ protected $sequenceId; protected $content; protected $timestamp; + protected $validate; public function __construct( array $params ) { if ( isset( $params['translationId'] ) ) { @@ -29,6 +30,9 @@ $this->timestamp = (int)$params['timestamp']; } else { $this->timestamp = wfTimestamp(); + } + if ( isset( $params['validate'] ) ) { + $this->validate = (bool)$params['validate']; } } @@ -72,4 +76,8 @@ public function getContent() { return $this->content; } + + public function getValidate() { + return $this->validate; + } } diff --git a/modules/translation/ext.cx.translation.storage.js b/modules/translation/ext.cx.translation.storage.js index 74ead77..365d103 100644 --- a/modules/translation/ext.cx.translation.storage.js +++ b/modules/translation/ext.cx.translation.storage.js @@ -18,6 +18,7 @@ ContentTranslationStorage.prototype.init = function () { this.sections = {}; + this.validationTracker = {}; this.listen(); }; @@ -163,8 +164,10 @@ if ( validations[ sectionId ] && Object.keys( validations[ sectionId ] ).length ) { $targetSection.data( 'errors', validations[ sectionId ] ); mw.hook( 'mw.cx.translation.validation.error' ).fire( $targetSection ); + this.validationTracker[ sectionId ].error = true; } else { $targetSection.removeData( 'errors' ); + this.validationTracker[ sectionId ].error = false; mw.hook( 'mw.cx.translation.validation.success' ).fire( $targetSection ); } } @@ -201,7 +204,8 @@ }; ContentTranslationStorage.prototype.markForSave = function ( $targetSection ) { - var $sourceSection, sourceSectionId, targetSectionId, sequenceId, state, origin; + var $sourceSection, sourceSectionId, targetSectionId, sequenceId,
[MediaWiki-commits] [Gerrit] Reduce the frequency of AbuseFilter Validations - change (mediawiki...ContentTranslation)
Santhosh has uploaded a new change for review. https://gerrit.wikimedia.org/r/277480 Change subject: Reduce the frequency of AbuseFilter Validations .. Reduce the frequency of AbuseFilter Validations The frequence fragment validation need Restbase and eventually parsoid to do the validations. Validating in every autosave will not be smart as per recent observations in the increase in requests to Restbase. Following approach is attempted: 1. In translation units that are sent to cxsave API for saving have a boolean typed validate flag. If true, it will be validated, otherwise skipped 2. The translation storage module will be responsible for setting that flag true or false 3. Do not set that flag true for sections other than paragraphs and target title. 4. Set the validate flag true in every 10th autosave 5. Set the validate flag true if the section has a validation error Bug: T129314 Change-Id: I8660527a891b77e272e9af1d6d3b0bbe3ee5ebf2 --- M api/ApiContentTranslationSave.php M includes/TranslationUnit.php M modules/translation/ext.cx.translation.storage.js 3 files changed, 36 insertions(+), 3 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation refs/changes/80/277480/1 diff --git a/api/ApiContentTranslationSave.php b/api/ApiContentTranslationSave.php index 3f31a97..e1ed70e 100644 --- a/api/ApiContentTranslationSave.php +++ b/api/ApiContentTranslationSave.php @@ -77,6 +77,9 @@ $checker = new AbuseFilterCheck( $this->getUser(), $title ); foreach ( $translationUnits as $translationUnit ) { + if ( !$translationUnit->getValidate() ) { + continue; + } $sectionId = $translationUnit->getSectionId(); if ( $sectionId === 'mwcx-source-title' ) { $validationResults[$sectionId] = @@ -190,7 +193,9 @@ // Content can be null in case translator clear the section. $tuData['content'] = null; } - + if ( !isset( $tuData['valdiate'] ) ) { + $tuData['valdiate'] = false; + } $tuData['translationId'] = $this->translation->getTranslationId(); $translationUnits[] = new TranslationUnit( $tuData ); } diff --git a/includes/TranslationUnit.php b/includes/TranslationUnit.php index 7a529b3..a4b72bd 100644 --- a/includes/TranslationUnit.php +++ b/includes/TranslationUnit.php @@ -16,6 +16,7 @@ protected $sequenceId; protected $content; protected $timestamp; + protected $validate; public function __construct( array $params ) { if ( isset( $params['translationId'] ) ) { @@ -30,6 +31,7 @@ } else { $this->timestamp = wfTimestamp(); } + $this->validate = (string)$params['validate']; } /** @@ -72,4 +74,8 @@ public function getContent() { return $this->content; } + + public function getValidate() { + return $this->validate; + } } diff --git a/modules/translation/ext.cx.translation.storage.js b/modules/translation/ext.cx.translation.storage.js index 74ead77..365d103 100644 --- a/modules/translation/ext.cx.translation.storage.js +++ b/modules/translation/ext.cx.translation.storage.js @@ -18,6 +18,7 @@ ContentTranslationStorage.prototype.init = function () { this.sections = {}; + this.validationTracker = {}; this.listen(); }; @@ -163,8 +164,10 @@ if ( validations[ sectionId ] && Object.keys( validations[ sectionId ] ).length ) { $targetSection.data( 'errors', validations[ sectionId ] ); mw.hook( 'mw.cx.translation.validation.error' ).fire( $targetSection ); + this.validationTracker[ sectionId ].error = true; } else { $targetSection.removeData( 'errors' ); + this.validationTracker[ sectionId ].error = false; mw.hook( 'mw.cx.translation.validation.success' ).fire( $targetSection ); } } @@ -201,7 +204,8 @@ }; ContentTranslationStorage.prototype.markForSave = function ( $targetSection ) { - var $sourceSection, sourceSectionId, targetSectionId, sequenceId, state, origin; + var $sourceSection, sourceSectionId, targetSectionId, sequenceId, state, origin, + validate; targetSectionId =