r88009 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88008‎ | r88009 | r88010 >
Date:17:12, 13 May 2011
Author:tparscal
Status:ok
Tags:
Comment:
Prevented loading data from the API until the user clicks on the "View page ratings" link in cases where we we aren't asking for user rating information anyways. This is used instead of loading when the tool is visible (the appear event), which should take lots of load off the API since most users have not rated and are anonymous (so we don't ask for user rating data) and far fewer people are going to click on the "View page ratings" link than scroll the ArticleFeedback tool into view.
Modified paths:
  • /trunk/extensions/ArticleFeedback/modules/jquery.articleFeedback/jquery.articleFeedback.js (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleFeedback/modules/jquery.articleFeedback/jquery.articleFeedback.js
@@ -14,6 +14,8 @@
1515 'ext.articleFeedback-options', mw.config.get( 'wgArticleFeedbackOptions' )
1616 );
1717
 18+var loadUserRatings = !mw.user.anonymous() || $.cookie( prefix( 'rated' ) ) === 'true';
 19+
1820 /**
1921 * Prefixes a key for cookies or events, with extension and version information
2022 *
@@ -191,6 +193,8 @@
192194 // For anon users, keep a cookie around so we know they've rated before
193195 if ( mw.user.anonymous() ) {
194196 $.cookie( prefix( 'rated' ), 'true', { 'expires': 365, 'path': '/' } );
 197+ // Ensure that user ratings are loaded from now on
 198+ loadUserRatings = true;
195199 }
196200 $.articleFeedback.fn.enableSubmission.call( context, false );
197201 context.$ui.find( '.articleFeedback-lock' ).show();
@@ -325,22 +329,21 @@
326330 },
327331 'load': function() {
328332 var context = this;
329 - var userrating = !mw.user.anonymous() || $.cookie( prefix( 'rated' ) ) === 'true';
330333 $.ajax( {
331334 'url': mw.config.get( 'wgScriptPath' ) + '/api.php',
332335 'type': 'GET',
333336 'dataType': 'json',
334337 'context': context,
335 - 'cache': !userrating,
 338+ 'cache': !loadUserRatings,
336339 'data': {
337340 'action': 'query',
338341 'format': 'json',
339342 'list': 'articlefeedback',
340343 'afpageid': mw.config.get( 'wgArticleId' ),
341 - 'afanontoken': userrating ? mw.user.id() : '',
342 - 'afuserrating': Number( userrating ),
 344+ 'afanontoken': loadUserRatings ? mw.user.id() : '',
 345+ 'afuserrating': Number( loadUserRatings ),
343346 'maxage': 0,
344 - 'smaxage': userrating ? 0 : mw.config.get( 'wgArticleFeedbackSMaxage' )
 347+ 'smaxage': loadUserRatings ? 0 : mw.config.get( 'wgArticleFeedbackSMaxage' )
345348 },
346349 'success': function( data ) {
347350 var context = this;
@@ -782,10 +785,16 @@
783786 if ( !showOptions ) {
784787 context.$ui.find( '.articleFeedback-options' ).hide();
785788 }
786 - // Show initial form and report values when the tool is visible
787 - context.$ui.appear( function() {
788 - $.articleFeedback.fn.load.call( context );
789 - } );
 789+ if ( loadUserRatings ) {
 790+ // Show initial form and report values when the tool is visible
 791+ context.$ui.appear( function() {
 792+ $.articleFeedback.fn.load.call( context );
 793+ } );
 794+ } else {
 795+ context.$ui.find( '.articleFeedback-switch-report' ).one( 'click', function() {
 796+ $.articleFeedback.fn.load.call( context );
 797+ } );
 798+ }
790799 }
791800 }
792801 };

Follow-up revisions

RevisionCommit summaryAuthorDate
r889091.17wmf1: MFT r88009catrope18:28, 26 May 2011

Status & tagging log