Lucas Werkmeister (WMDE) has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/364215 )

Change subject: Check constraint parameters of saved constraint statements
......................................................................

Check constraint parameters of saved constraint statements

The gadget now checks constraint parameters when statements on a
property are saved. Since constraint statements are processed
asynchronously by a job, this is done after a certain delay; if the
constraint is found to not exist, the delay is increased and the request
repeated.

The delay-increment logic should work fine for added constraint
statements (repeat the request until the constraint statement has been
processed and is found), but can’t work for edited constraint
statements: those will always return a result, either for the old
version of the constraint (if the API call happens before the update has
been processed) or for the new one (otherwise). We can’t distinguish
between these cases, so the initial delay has to hit a balance between
being long enough that the job has likely run, and short enough that the
parameter report is still useful. According to Grafana [1], the 50th
percentile job wait time is usually well below one second, so an initial
delay of three seconds is hopefully an acceptable choice.

The ESLint rule no-use-before-define is disabled for functions, since
this commit introduces a call cycle between two functions, which cannot
be linearized into an order where no function calls another function
defined after it.

[1]: 
https://grafana.wikimedia.org/dashboard/db/job-queue-health?panelId=7&fullscreen

Change-Id: Ifaccdd18a33ae88c4214f50b9db3d6d1c997c7d1
---
M .eslintrc.json
M modules/gadget.js
2 files changed, 34 insertions(+), 2 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseQualityConstraints
 refs/changes/15/364215/1

diff --git a/.eslintrc.json b/.eslintrc.json
index a03258b..047dbee 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -11,6 +11,7 @@
        "rules": {
                "keyword-spacing": "off",
                "space-before-function-paren": "off",
-               "wrap-iife": "off"
+               "wrap-iife": "off",
+               "no-use-before-define": [ "error", "nofunc" ]
        }
 }
diff --git a/modules/gadget.js b/modules/gadget.js
index c08af01..2cf6a32 100644
--- a/modules/gadget.js
+++ b/modules/gadget.js
@@ -1,7 +1,8 @@
 ( function( mw, $, OO ) {
        'use strict';
 
-       var entityId;
+       var entityId,
+               constraintParameterDelays = [];
 
        function buildWidget( reports, messageKey, flags /* = '' */ ) {
                var widget = new OO.ui.PopupButtonWidget( {
@@ -78,6 +79,26 @@
                } );
        }
 
+       function scheduleConstraintParameterCheck( constraintId ) {
+               var propertyId = constraintId.match( /^(.*)\$/ )[ 1 ],
+                       delay = constraintParameterDelays[ constraintId ] || 3;
+               constraintParameterDelays[ constraintId ] = delay + 1;
+
+               setTimeout(
+                       function() {
+                               new mw.Api().get( {
+                                       action: 'wbcheckconstraintparameters',
+                                       format: 'json',
+                                       uselang: mw.config.get( 
'wgUserLanguage' ),
+                                       constraintid: constraintId
+                               } ).then( function( data ) {
+                                       addParameterReports( 
data.wbcheckconstraintparameters[ propertyId ] );
+                               } );
+                       },
+                       delay * 1000
+               );
+       }
+
        function addReportsToStatement( entityData, $statement ) {
                var match = $statement.parents( '.wikibase-statementview' )[ 0 
].className.match(
                                /\bwikibase-statement-([^\s$]+\$[\dA-F-]+)\b/i
@@ -125,6 +146,14 @@
 
                for ( constraintId in parameterReports ) {
                        status = parameterReports[ constraintId ].status;
+                       if ( status === 'not-found' ) {
+                               // could be a new constraint that has not been 
processed yet, try again later
+                               scheduleConstraintParameterCheck( constraintId 
);
+                               continue;
+                       } else {
+                               // reset delay for this constraint
+                               delete constraintParameterDelays[ constraintId 
];
+                       }
                        if ( status === 'okay' ) {
                                continue;
                        }
@@ -197,6 +226,8 @@
                                $( '.wikibase-statementgroupview .' + 
statementClass + ' .wikibase-statementview-mainsnak .wikibase-snakview-value' )
                                        .each( function () { 
addReportsToStatement( data.wbcheckconstraints[ entityId ], $( this ) ); } );
                        } );
+
+                       scheduleConstraintParameterCheck( statementId );
                } );
        } );
 } )( mediaWiki, jQuery, OO );

-- 
To view, visit https://gerrit.wikimedia.org/r/364215
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifaccdd18a33ae88c4214f50b9db3d6d1c997c7d1
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikibaseQualityConstraints
Gerrit-Branch: master
Gerrit-Owner: Lucas Werkmeister (WMDE) <lucas.werkmeis...@wikimedia.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to