From f965246b83a85064da222da0392f68296352d89e Mon Sep 17 00:00:00 2001 From: Thomas Heartman Date: Mon, 19 Aug 2024 09:13:30 +0200 Subject: [PATCH] chore: minor cleanup in new project read model (#7911) This PR touches up a few small things in the project read model. Fixes: Use the right method name in the query/method timer for `getProjectsForAdminUi`. I'd forgotten to change the timer name from the original method name. Spells the method name correctly for the `getMembersCount` timer (it used to be `getMemberCount`, but the method is callled `getMembersCount` with a plural s). Changes: Call the `getMembersCount` timer from within the `getMembersCount` method itself. Instead of setting that timer up from two different places, we can call it in the method we're timing. This wasn't a problem previously, because the method was only called from a single place. Assuming we always wanna time that query, it makes more sense to put the timing in the actual method. --- src/lib/features/project/project-read-model.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/lib/features/project/project-read-model.ts b/src/lib/features/project/project-read-model.ts index e6e6f47c75..ceca2b6748 100644 --- a/src/lib/features/project/project-read-model.ts +++ b/src/lib/features/project/project-read-model.ts @@ -66,7 +66,7 @@ export class ProjectReadModel implements IProjectReadModel { query?: IProjectQuery, userId?: number, ): Promise { - const projectTimer = this.timer('getProjectsForProjectList'); + const projectTimer = this.timer('getProjectsForAdminUi'); let projects = this.db(TABLE) .leftJoin('features', 'features.project', 'projects.id') .leftJoin( @@ -129,10 +129,8 @@ export class ProjectReadModel implements IProjectReadModel { const projectsWithFeatureCount = projectAndFeatureCount.map(mapProjectForUi); projectTimer(); - const memberTimer = this.timer('getMemberCount'); const memberCount = await this.getMembersCount(); - memberTimer(); const memberMap = new Map( memberCount.map((c) => [c.project, Number(c.count)]), ); @@ -193,10 +191,8 @@ export class ProjectReadModel implements IProjectReadModel { mapProjectForInsights, ); projectTimer(); - const memberTimer = this.timer('getMemberCount'); const memberCount = await this.getMembersCount(); - memberTimer(); const memberMap = new Map( memberCount.map((c) => [c.project, Number(c.count)]), ); @@ -210,6 +206,7 @@ export class ProjectReadModel implements IProjectReadModel { } private async getMembersCount(): Promise { + const memberTimer = this.timer('getMembersCount'); const members = await this.db .select('project') .from((db) => { @@ -231,6 +228,8 @@ export class ProjectReadModel implements IProjectReadModel { }) .groupBy('project') .count('user_id'); + + memberTimer(); return members; } }