Skip to content

Commit

Permalink
Perf 🔥
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentlaine committed Mar 22, 2024
1 parent 0386bfb commit 1430b90
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 21 deletions.
3 changes: 0 additions & 3 deletions src/arrete_cadre/arrete_cadre.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,6 @@ export class ArreteCadreService {
descriptionAlerteRenforcee: true,
descriptionCrise: true,
},
arretesRestriction: {
id: true,
},
},
relations: [
'zonesAlerte',
Expand Down
3 changes: 3 additions & 0 deletions src/arrete_cadre/dto/arrete_cadre.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ export const arreteCadrePaginateConfig: PaginateConfig<ArreteCadre> = {
'arretesRestriction.id',
'arretesRestriction.numero',
'arretesRestriction.statut',
'arretesRestriction.departement.id',
'arretesRestriction.departement.code',
'zonesAlerte.id',
'zonesAlerte.disabled',
],
Expand All @@ -114,6 +116,7 @@ export const arreteCadrePaginateConfig: PaginateConfig<ArreteCadre> = {
'zonesAlerte',
'departements',
'arretesRestriction',
'arretesRestriction.departement',
'departementPilote',
],
searchableColumns: ['numero', 'departements.nom', 'departements.code'],
Expand Down
1 change: 1 addition & 0 deletions src/arrete_restriction/arrete_restriction.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ export class ArreteRestrictionService {
return this.arreteRestrictionRepository.find({
select: {
id: true,
numero: true,
statut: true,
restrictions: {
id: true,
Expand Down
21 changes: 3 additions & 18 deletions src/usage/usage.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ export class UsageService {
}

async findAll(curentUser: User): Promise<Usage[]> {
const usages = await this.usageRepository
return await this.usageRepository
.createQueryBuilder('usage')
.select()
.distinctOn(['usage.nom'])
.leftJoinAndSelect('usage.thematique', 'thematique')
.leftJoin('usage.arreteCadre', 'arreteCadre')
.leftJoin('arreteCadre.departements', 'departements')
Expand All @@ -36,24 +37,8 @@ export class UsageService {
code_dep: curentUser.role_departement,
},
)
.orWhere('usage."isTemplate" = true')
.orderBy('usage.nom', 'ASC')
.getMany();

// Suppression des doublons, problèmes de perf avec DISTINCT via la requête SQL
return usages.filter((value, index, self) =>
index === self.findIndex((t) => (
t.nom === value.nom
))
).sort((a, b) => {
if (a.nom < b.nom) {
return -1;
}
if (a.nom > b.nom) {
return 1;
}
return 0;
})
.getMany()
}

async create(usage: CreateUpdateUsageDto): Promise<Usage> {
Expand Down

0 comments on commit 1430b90

Please sign in to comment.