Merge "Delay API requests for preloading metadata until user interaction"

This commit is contained in:
jenkins-bot 2023-01-06 21:46:34 +00:00 committed by Gerrit Code Review
commit d7fe1c7979
2 changed files with 21 additions and 9 deletions

View file

@ -27,6 +27,10 @@ function ReplyLinksController( $pageContainer ) {
replyButton.on( 'click', controller.onReplyButtonClickHandler, [ replyButton ] );
} );
this.$replyLinkSets.on( 'focusin mouseover touchstart', function () {
controller.emit( 'link-interact' );
} );
// "Add topic" link in the skin interface
if ( featuresEnabled.newtopictool ) {
// eslint-disable-next-line no-jquery/no-global-selector
@ -34,6 +38,10 @@ function ReplyLinksController( $pageContainer ) {
if ( $addSectionTab.length ) {
this.$addSectionLink = $addSectionTab.find( 'a' );
this.$addSectionLink.on( 'click keypress', this.onAddSectionLinkClickHandler );
this.$addSectionLink.on( 'focusin mouseover touchstart', function () {
controller.emit( 'link-interact' );
} );
}
// Handle events on all links that potentially open the new section interface,
// including links in the page content (from templates) or from gadgets.

View file

@ -252,6 +252,19 @@ function init( $container, state ) {
$pageContainer = $container;
linksController = new ReplyLinksController( $pageContainer );
linksController.on( 'link-interact', function () {
// Preload page metadata when the user is about to use a link, to make the tool load faster.
// NOTE: As of January 2023, this is an EXPENSIVE API CALL. It must not be done on every
// pageview, as that would generate enough load to take down Wikimedia sites (T325477).
// It would be barely acceptable to do it on every *discussion* pageview, but we're trying
// to be better and only do it when really needed (T325598).
getPageData(
mw.config.get( 'wgRelevantPageName' ),
mw.config.get( 'wgCurRevisionId' )
);
} );
var parser = new Parser( require( './parser/data.json' ) );
var commentNodes = $pageContainer[ 0 ].querySelectorAll( '[data-mw-thread-id]' );
@ -419,15 +432,6 @@ function init( $container, state ) {
}
} );
// Preload page metadata.
// TODO: Isn't this too early to load it? We will only need it if the user tries replying...
if ( mw.config.get( 'wgDiscussionToolsPageThreads' ) ) {
getPageData(
mw.config.get( 'wgRelevantPageName' ),
mw.config.get( 'wgCurRevisionId' )
);
}
// Page-level handlers only need to be setup once
if ( !pageHandlersSetup ) {
$( window ).on( 'popstate', function () {