From 0fc474d66f1cf0e8683f8f9ca5b0a0eb021a6b19 Mon Sep 17 00:00:00 2001 From: David Lynch Date: Wed, 6 Apr 2022 11:37:29 -0500 Subject: [PATCH] Log saveSuccess more consistently Cases where saveSuccess wasn't logged: * creating a new page with the New Topic tool * any replies on mobile * successful replies made through transclusions which then couldn't purge the current page These were all cases where we abandoned the post-save process early to reload the page. Bug: T305541 Change-Id: I1366a3e0a4b03ac67f926284f1aa718ae552d852 --- modules/controller.js | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/modules/controller.js b/modules/controller.js index a7ad0086d..63f628a4f 100644 --- a/modules/controller.js +++ b/modules/controller.js @@ -491,6 +491,15 @@ function refreshPageContents( oldId ) { * @param {mw.dt.ReplyWidget} replyWidget ReplyWidget */ function update( data, threadItem, pageName, replyWidget ) { + function logSaveSuccess() { + logger( { + action: 'saveSuccess', + timing: mw.now() - replyWidget.saveInitiated, + // eslint-disable-next-line camelcase + revision_id: data.newrevid + } ); + } + // We posted a new comment, clear the cache, because wgCurRevisionId will not change if we posted // to a transcluded page (T266275) pageDataCache[ mw.config.get( 'wgRelevantPageName' ) ][ mw.config.get( 'wgCurRevisionId' ) ] = null; @@ -505,6 +514,7 @@ function update( data, threadItem, pageName, replyWidget ) { replyWidget.clearStorage(); replyWidget.setPending( true ); window.location = mw.util.getUrl( pageName, { dtrepliedto: threadItem.id } ); + logSaveSuccess(); return; } @@ -517,6 +527,7 @@ function update( data, threadItem, pageName, replyWidget ) { // MobileFrontend does not use the 'wikipage.content' hook, and its interface will not // re-initialize properly (e.g. page sections won't be collapsible). Reload the whole page. window.location = mw.util.getUrl( pageName, { dtrepliedto: threadItem.id } ); + logSaveSuccess(); return; } @@ -559,6 +570,8 @@ function update( data, threadItem, pageName, replyWidget ) { // We saved the reply, but couldn't purge or fetch the updated page. Seems difficult to // explain this problem. Redirect to the page where the user can at least see their reply… window.location = mw.util.getUrl( pageName, { dtrepliedto: threadItem.id } ); + // We're confident the saving portion succeeded, so still log this: + logSaveSuccess(); } ); } @@ -574,14 +587,7 @@ function update( data, threadItem, pageName, replyWidget ) { ); } - pageUpdated.then( function () { - logger( { - action: 'saveSuccess', - timing: mw.now() - replyWidget.saveInitiated, - // eslint-disable-next-line camelcase - revision_id: data.newrevid - } ); - } ); + pageUpdated.then( logSaveSuccess ); } module.exports = {