Skip to content

Commit

Permalink
fix(#9226): fix telemetry for task refresh (#9228)
Browse files Browse the repository at this point in the history
  • Loading branch information
latin-panda authored Jul 2, 2024
1 parent 9f90022 commit 53d1b21
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
1 change: 1 addition & 0 deletions webapp/src/ts/effects/reports.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export class ReportsEffects {
name: [ 'report_detail', model?.doc?.form, 'load' ].join(':'),
recordApdex: true,
});
this.trackOpenReport = null;
}

return of(this.reportActions.setRightActionBar());
Expand Down
31 changes: 22 additions & 9 deletions webapp/src/ts/modules/tasks/tasks.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export class TasksComponent implements OnInit, OnDestroy {
subscription = new Subscription();
private tasksActions;
private globalActions;
private trackPerformance;
private trackLoadPerformance;
private trackRefreshPerformance;

tasksList;
selectedTask;
Expand Down Expand Up @@ -93,7 +94,7 @@ export class TasksComponent implements OnInit, OnDestroy {
}

ngOnInit() {
this.trackPerformance = this.performanceService.track();
this.trackLoadPerformance = this.performanceService.track();
this.tasksActions.setSelectedTask(null);
this.subscribeToStore();
this.subscribeToChanges();
Expand All @@ -107,7 +108,6 @@ export class TasksComponent implements OnInit, OnDestroy {

ngOnDestroy() {
this.subscription.unsubscribe();

this.tasksActions.setTasksList([]);
this.tasksActions.setTasksLoaded(false);
this.tasksActions.setSelectedTask(null);
Expand All @@ -133,10 +133,12 @@ export class TasksComponent implements OnInit, OnDestroy {

private async refreshTasks() {
try {
if (this.tasksLoaded) {
this.trackRefreshPerformance = this.performanceService.track();
}
const isEnabled = await this.rulesEngineService.isEnabled();
this.tasksDisabled = !isEnabled;
const taskDocs = isEnabled ? await this.rulesEngineService.fetchTaskDocsForAllContacts() : [];

this.hasTasks = taskDocs.length > 0;

const hydratedTasks = await this.hydrateEmissions(taskDocs) || [];
Expand All @@ -157,17 +159,28 @@ export class TasksComponent implements OnInit, OnDestroy {
this.tasksActions.setTasksList([]);
} finally {
this.loading = false;
const performanceName = this.tasksLoaded ? 'tasks:refresh' : 'tasks:load';
this.trackPerformance?.stop({
name: performanceName,
recordApdex: true,
});
this.recordPerformance();
if (!this.tasksLoaded) {
this.tasksActions.setTasksLoaded(true);
}
}
}

private recordPerformance() {
if (this.tasksLoaded) {
this.trackRefreshPerformance?.stop({
name: ['tasks', 'refresh'].join(':'),
recordApdex: true,
});
return;
}

this.trackLoadPerformance?.stop({
name: ['tasks', 'load'].join(':'),
recordApdex: true,
});
}

listTrackBy(index, task) {
return task?._id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ describe('TasksComponent', () => {
flush();

expect(rulesEngineService.fetchTaskDocsForAllContacts.callCount).to.eq(2);
expect(performanceService.track.calledOnce).to.be.true;
expect(performanceService.track.calledTwice).to.be.true;
expect(stopPerformanceTrackStub.calledTwice).to.be.true;
expect(stopPerformanceTrackStub.args[0][0]).to.deep.equal({ name: 'tasks:load', recordApdex: true });
expect(stopPerformanceTrackStub.args[1][0]).to.deep.equal({ name: 'tasks:refresh', recordApdex: true });
Expand Down

0 comments on commit 53d1b21

Please sign in to comment.