Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Move Documents load time and emit meaningful content timestamp #1460

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/lib/Preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -1583,14 +1583,17 @@ class Preview extends EventEmitter {
const contentLoadTime = Timer.get(contentLoadTag) || {};
const previewLoadTime = Timer.get(previewLoadTag) || {};

const { elapsed: contentLoadTimeDuration, end: meaningfulContentTimestamp } = contentLoadTime;

this.emitLogEvent(PREVIEW_METRIC, {
encoding,
event_name: LOAD_METRIC.previewLoadEvent,
value: previewLoadTime.elapsed || 0,
[LOAD_METRIC.fileInfoTime]: infoTime.elapsed || 0,
[LOAD_METRIC.convertTime]: convertTime.elapsed || 0,
[LOAD_METRIC.downloadResponseTime]: downloadTime.elapsed || 0,
[LOAD_METRIC.contentLoadTime]: contentLoadTime.elapsed || 0,
[LOAD_METRIC.contentLoadTime]: contentLoadTimeDuration || 0,
[LOAD_METRIC.meaningfulContentTimestamp]: meaningfulContentTimestamp,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be contentLoadTimestamp to stay consistent with its other attribute? Should it default to 0, as well?

});

Timer.reset([infoTag, convertTag, downloadTag, contentLoadTag, previewLoadTag]);
Expand Down
2 changes: 2 additions & 0 deletions src/lib/__tests__/Preview-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2350,6 +2350,7 @@ describe('lib/Preview', () => {
preview.file = {
id: fileId,
};
jest.spyOn(Timer, 'get').mockImplementation(() => ({ elapsed: 10, end: 123 }));
});

afterEach(() => {
Expand Down Expand Up @@ -2386,6 +2387,7 @@ describe('lib/Preview', () => {
expect(metric[LOAD_METRIC.convertTime]).toBeDefined();
expect(metric[LOAD_METRIC.downloadResponseTime]).toBeDefined();
expect(metric[LOAD_METRIC.contentLoadTime]).toBeDefined();
expect(metric[LOAD_METRIC.meaningfulContentTimestamp]).toBeDefined();
expect(metric.value).toBeDefined();
done();
});
Expand Down
1 change: 1 addition & 0 deletions src/lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export const LOAD_METRIC = {
convertTime: 'convert_time', // Time it took from receiving file info to being able to request the rep.
downloadResponseTime: 'download_response_time', // Time it took for TTFB when requesting a rep.
fileInfoTime: 'file_info_time', // Round trip time from file info request to received file info.
meaningfulContentTimestamp: 'meaningful_content_timestamp', // Timestamp of when meaningful content was loaded
preloadTime: 'preload_time', // How long it takes to preload the document.
previewLoadEvent: 'load', // Event name for preview_metric events related to loading times.
previewLoadTime: 'preview_loading', // Total preview load time. Maps to "value" of load event
Expand Down
15 changes: 8 additions & 7 deletions src/lib/viewers/doc/DocBaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1162,8 +1162,6 @@ class DocBaseViewer extends BaseViewer {
this.pdfViewer.currentScaleValue = 'auto';
this.loadUI();

const { pagesCount, currentScale } = this.pdfViewer;

// Set page to the user-defined page, previously opened page, or first page
const startPage = this.startPageNum || this.getCachedPage();
this.setPage(startPage);
Expand All @@ -1174,11 +1172,6 @@ class DocBaseViewer extends BaseViewer {
// Broadcast that preview has 'loaded' when page structure is available
if (!this.loaded) {
this.loaded = true;
this.emit(VIEWER_EVENT.load, {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this affect our existing metrics?

encoding: this.encoding,
numPages: pagesCount,
scale: currentScale,
});

// Add page IDs to each page after page structure is available
this.setupPageIds();
Expand Down Expand Up @@ -1238,6 +1231,14 @@ class DocBaseViewer extends BaseViewer {
this.hidePreload();
this.somePageRendered = true;

const { pagesCount, currentScale } = this.pdfViewer;

this.emit(VIEWER_EVENT.load, {
encoding: this.encoding,
numPages: pagesCount,
scale: currentScale,
});

if (this.options.enableThumbnailsSidebar) {
this.initThumbnails();
this.resize();
Expand Down
34 changes: 17 additions & 17 deletions src/lib/viewers/doc/__tests__/DocBaseViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1884,23 +1884,6 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => {
expect(stubs.setupPages).toBeCalled();
});

test("should broadcast that the preview is loaded if it hasn't already", () => {
docBase.pdfViewer = {
currentScale: 'unknown',
};
docBase.loaded = false;
docBase.pdfViewer.pagesCount = 5;
docBase.encoding = 'gzip';

docBase.pagesinitHandler();
expect(stubs.emit).toBeCalledWith(VIEWER_EVENT.load, {
encoding: docBase.encoding,
numPages: 5,
scale: 'unknown',
});
expect(docBase.loaded).toBe(true);
});

test('should set the start page based', () => {
const START_PAGE_NUM = 2;
const PAGES_COUNT = 3;
Expand Down Expand Up @@ -1970,6 +1953,23 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => {
expect(stubs.initThumbnails).not.toBeCalled();
expect(docBase.renderUI).toBeCalled();
});

test("should broadcast that the preview is loaded if it hasn't already", () => {
docBase.pdfViewer = {
currentScale: 'unknown',
};
docBase.loaded = false;
docBase.pdfViewer.pagesCount = 5;
docBase.encoding = 'gzip';

docBase.pagerenderedHandler(docBase.event);
expect(stubs.emit).toBeCalledWith(VIEWER_EVENT.load, {
encoding: docBase.encoding,
numPages: 5,
scale: 'unknown',
});
expect(docBase.somePageRendered).toBe(true);
});
});

describe('pagechangingHandler()', () => {
Expand Down