mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-25 00:07:47 +01:00
refactor: use promise.all instead of sequential awaited calls (#8316)
This PR follows up on a comment made in https://github.com/Unleash/unleash/pull/8314 and groups sequential awaited calls into a single Promise.all instead.
This commit is contained in:
parent
e51e6cc507
commit
4c4b4aa922
@ -12,6 +12,7 @@ import type { IPrivateProjectChecker } from '../private-project/privateProjectCh
|
||||
import type {
|
||||
IAccessStore,
|
||||
IAccountStore,
|
||||
IEvent,
|
||||
IEventStore,
|
||||
IOnboardingReadModel,
|
||||
MinimalUser,
|
||||
@ -19,6 +20,7 @@ import type {
|
||||
import type { FeatureEventFormatter } from '../../addons/feature-event-formatter-md';
|
||||
import { generateImageUrl } from '../../util';
|
||||
import type { PersonalDashboardProjectDetailsSchema } from '../../openapi';
|
||||
import type { IRoleWithProject } from '../../types/stores/access-store';
|
||||
|
||||
export class PersonalDashboardService {
|
||||
private personalDashboardReadModel: IPersonalDashboardReadModel;
|
||||
@ -103,32 +105,16 @@ export class PersonalDashboardService {
|
||||
userId: number,
|
||||
projectId: string,
|
||||
): Promise<PersonalDashboardProjectDetailsSchema> {
|
||||
const recentEvents = await this.eventStore.searchEvents(
|
||||
{ limit: 4, offset: 0 },
|
||||
[{ field: 'project', operator: 'IS', values: [projectId] }],
|
||||
);
|
||||
|
||||
const onboardingStatus =
|
||||
await this.onboardingReadModel.getOnboardingStatusForProject(
|
||||
projectId,
|
||||
);
|
||||
|
||||
const formattedEvents = recentEvents.map((event) => ({
|
||||
const formatEvents = (recentEvents: IEvent[]) =>
|
||||
recentEvents.map((event) => ({
|
||||
summary: this.featureEventFormatter.format(event).text,
|
||||
createdBy: event.createdBy,
|
||||
id: event.id,
|
||||
createdByImageUrl: generateImageUrl({ email: event.createdBy }),
|
||||
}));
|
||||
|
||||
const owners =
|
||||
await this.projectOwnersReadModel.getProjectOwners(projectId);
|
||||
|
||||
const allRoles = await this.accessStore.getAllProjectRolesForUser(
|
||||
userId,
|
||||
projectId,
|
||||
);
|
||||
|
||||
const projectRoles = allRoles
|
||||
const filterRoles = (allRoles: IRoleWithProject[]) =>
|
||||
allRoles
|
||||
.filter((role) => ['project', 'custom'].includes(role.type))
|
||||
.map((role) => ({
|
||||
id: role.id,
|
||||
@ -136,11 +122,30 @@ export class PersonalDashboardService {
|
||||
type: role.type as PersonalDashboardProjectDetailsSchema['roles'][number]['type'],
|
||||
}));
|
||||
|
||||
const healthScores =
|
||||
await this.personalDashboardReadModel.getLatestHealthScores(
|
||||
const [latestEvents, onboardingStatus, owners, roles, healthScores] =
|
||||
await Promise.all([
|
||||
this.eventStore
|
||||
.searchEvents({ limit: 4, offset: 0 }, [
|
||||
{
|
||||
field: 'project',
|
||||
operator: 'IS',
|
||||
values: [projectId],
|
||||
},
|
||||
])
|
||||
.then(formatEvents),
|
||||
this.onboardingReadModel.getOnboardingStatusForProject(
|
||||
projectId,
|
||||
),
|
||||
this.projectOwnersReadModel.getProjectOwners(projectId),
|
||||
this.accessStore
|
||||
.getAllProjectRolesForUser(userId, projectId)
|
||||
.then(filterRoles),
|
||||
this.personalDashboardReadModel.getLatestHealthScores(
|
||||
projectId,
|
||||
8,
|
||||
);
|
||||
),
|
||||
]);
|
||||
|
||||
let avgHealthCurrentWindow: number | null = null;
|
||||
let avgHealthPastWindow: number | null = null;
|
||||
|
||||
@ -161,10 +166,10 @@ export class PersonalDashboardService {
|
||||
}
|
||||
|
||||
return {
|
||||
latestEvents: formattedEvents,
|
||||
latestEvents,
|
||||
onboardingStatus,
|
||||
owners,
|
||||
roles: projectRoles,
|
||||
roles,
|
||||
insights: {
|
||||
avgHealthCurrentWindow,
|
||||
avgHealthPastWindow,
|
||||
|
Loading…
Reference in New Issue
Block a user