Track how long it takes to open a preview

The search platform is working on creating SLI's around various search
use cases, including search previews. Add a metric that times how long
it takes between initiating and finishing a preview load.

Bug: T335499
Change-Id: I79ffae7155ab99180c8cd2d4d7503a1593a5daca
这个提交包含在:
Erik Bernhardson 2023-08-11 09:55:48 -07:00 提交者 Ebernhardson
父节点 13aebf0927
当前提交 64821c96a5
共有 3 个文件被更改,包括 57 次插入4 次删除

查看文件

@ -73,6 +73,7 @@
"resources/stores/Query.js",
"resources/stores/Root.js",
"resources/stores/Dom.js",
"resources/stores/Timing.js",
{
"name": "codex-icons.json",
"callback": "MediaWiki\\ResourceLoader\\CodexModule::getIcons",

查看文件

@ -27,7 +27,8 @@ const AppViewMobile = require( './AppViewMobile.vue' ),
useEventStore = require( '../stores/Event.js' ),
useRootStore = require( '../stores/Root.js' ),
useDomStore = require( '../stores/Dom.js' ),
useRequestStatusStore = require( '../stores/RequestStatus.js' );
useRequestStatusStore = require( '../stores/RequestStatus.js' ),
useTimingStore = require( '../stores/Timing.js' );
// @vue/component
module.exports = exports = {
@ -54,7 +55,8 @@ module.exports = exports = {
mapState( useRootStore, [
'isMobile',
'title',
'results'
'results',
'visible'
] ),
mapState( useRequestStatusStore, [
'loading'
@ -130,6 +132,8 @@ module.exports = exports = {
watch: {
title: {
handler( title ) {
const timingStore = useTimingStore();
timingStore.reset();
if ( title ) {
this.setQueryQuickViewTitle();
}
@ -138,12 +142,22 @@ module.exports = exports = {
},
loading: {
handler( loading ) {
// We re-calculate the tabbable element everytime the loading is complete.
if ( !loading ) {
if ( loading ) {
useTimingStore().start();
} else {
// We re-calculate the tabbable element everytime the loading is complete.
this.updateTabbableElements();
useTimingStore().complete();
}
},
flush: 'post'
},
visible: {
handler( visible ) {
if ( !visible ) {
useTimingStore().reset();
}
}
}
},
created() {

38
resources/stores/Timing.js 普通文件
查看文件

@ -0,0 +1,38 @@
'use strict';
const Pinia = require( 'pinia' );
const useTimingStore = Pinia.defineStore( 'timing', {
state: () => ( {
startTime: 0
} ),
getters: {
},
actions: {
/**
* Marks when loading started
*/
start() {
this.startTime = performance.now();
},
/**
* Reports load timing, if available
*/
complete() {
if ( !this.startTime ) {
return;
}
const took = performance.now() - this.startTime;
mw.track( 'timing.SearchVue.LoadPreview', took );
this.reset();
},
/**
* Reset the current timing
*/
reset() {
this.startTime = 0;
}
}
} );
module.exports = useTimingStore;