Skip to content

Commit

Permalink
Remove index 🔥
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentlaine committed Mar 21, 2024
1 parent 5ff454e commit 0386bfb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/usage/entities/usage.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export class Usage extends BaseEntity {
id: number;

@Column({ nullable: false, length: 255 })
@Index()
nom: string;

@ManyToOne(() => Thematique,
Expand Down
20 changes: 17 additions & 3 deletions src/usage/usage.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ export class UsageService {
});
}

findAll(curentUser: User): Promise<Usage[]> {
return this.usageRepository
async findAll(curentUser: User): Promise<Usage[]> {
const usages = await this.usageRepository
.createQueryBuilder('usage')
.select()
.distinctOn(['usage.nom'])
.leftJoinAndSelect('usage.thematique', 'thematique')
.leftJoin('usage.arreteCadre', 'arreteCadre')
.leftJoin('arreteCadre.departements', 'departements')
Expand All @@ -40,6 +39,21 @@ export class UsageService {
.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;
})
}

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

0 comments on commit 0386bfb

Please sign in to comment.