Skip to content

Commit 626bfa5

Browse files
authored
Move the one performance metric in page to exit to avoid join (#17784)
1 parent e68e6a5 commit 626bfa5

3 files changed

Lines changed: 19 additions & 19 deletions

File tree

javascripts/events.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export function getUserEventsId () {
3030
export function sendEvent ({
3131
type,
3232
version = '1.0.0',
33-
page_render_duration,
33+
exit_render_duration,
3434
exit_first_paint,
3535
exit_dom_interactive,
3636
exit_dom_complete,
@@ -81,9 +81,10 @@ export function sendEvent ({
8181
},
8282

8383
// Page event
84-
page_render_duration,
84+
// No extra fields
8585

8686
// Exit event
87+
exit_render_duration,
8788
exit_first_paint,
8889
exit_dom_interactive,
8990
exit_dom_complete,
@@ -150,12 +151,14 @@ function sendExit () {
150151
if (document.visibilityState !== 'hidden') return
151152
sentExit = true
152153
const {
154+
render,
153155
firstContentfulPaint,
154156
domInteractive,
155157
domComplete
156158
} = getPerformance()
157159
return sendEvent({
158160
type: 'exit',
161+
exit_render_duration: render,
159162
exit_first_paint: firstContentfulPaint,
160163
exit_dom_interactive: domInteractive,
161164
exit_dom_complete: domComplete,
@@ -165,11 +168,7 @@ function sendExit () {
165168
}
166169

167170
function initPageEvent () {
168-
const { render } = getPerformance()
169-
const pageEvent = sendEvent({
170-
type: 'page',
171-
page_render_duration: render
172-
})
171+
const pageEvent = sendEvent({ type: 'page' })
173172
pageEventId = pageEvent?.context?.event_id
174173
}
175174

lib/schema-event.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,6 @@ const pageSchema = {
124124
type: {
125125
type: 'string',
126126
pattern: '^page$'
127-
},
128-
page_render_duration: {
129-
type: 'number',
130-
description: 'How long the server took to render the page content, in seconds.',
131-
minimum: 0.001
132127
}
133128
}
134129
}
@@ -145,6 +140,11 @@ const exitSchema = {
145140
type: 'string',
146141
pattern: '^exit$'
147142
},
143+
exit_render_duration: {
144+
type: 'number',
145+
description: 'How long the server took to render the page content, in seconds.',
146+
minimum: 0.001
147+
},
148148
exit_first_paint: {
149149
type: 'number',
150150
minimum: 0.001,

tests/rendering/events.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -280,19 +280,13 @@ describe('POST /events', () => {
280280
}
281281
}, 400)
282282
)
283-
284-
it('should page_render_duration is a positive number', () =>
285-
checkEvent({
286-
...pageExample,
287-
page_render_duration: -0.5
288-
}, 400)
289-
)
290283
})
291284

292285
describe('exit', () => {
293286
const exitExample = {
294287
...baseExample,
295288
type: 'exit',
289+
exit_render_duration: 0.9,
296290
exit_first_paint: 0.1,
297291
exit_dom_interactive: 0.2,
298292
exit_dom_complete: 0.3,
@@ -304,6 +298,13 @@ describe('POST /events', () => {
304298
checkEvent(exitExample, 201)
305299
)
306300

301+
it('should exit_render_duration is a positive number', () =>
302+
checkEvent({
303+
...exitExample,
304+
exit_render_duration: -0.5
305+
}, 400)
306+
)
307+
307308
it('exit_first_paint is a number', () =>
308309
checkEvent({ ...exitExample, exit_first_paint: 'afjdkl' }, 400)
309310
)

0 commit comments

Comments
 (0)