mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-24 08:23:52 +00:00
Merge "Delay API requests for preloading metadata until user interaction"
This commit is contained in:
commit
d7fe1c7979
|
@ -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.
|
||||
|
|
|
@ -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 () {
|
||||
|
|
Loading…
Reference in a new issue