Skip to content

Commit

Permalink
fix(backend): delete useless indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
pYassine committed Jul 24, 2024
1 parent dc0deba commit b2c461a
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 34 deletions.
4 changes: 3 additions & 1 deletion .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ fileignoreconfig:
checksum: 2c8af8c1e2a41dd8ffdec224601f6c61a7ca4ce89f39e0f91072bb3f6736232c
- filename: packages/backend/src/_migrations/1720558050667-auto-migration.ts
checksum: 3b2a7e24e6e69fb3b81f473ceb43a00a2191c0358f2cbc314f5eb3b0e2a95672
- filename: packages/backend/src/_migrations/1721817064651-auto-migration.ts
checksum: 4c1f4f912bebc23465a8ed8bf0729091774483f2c15025b60f7cbe7a4cbd0d12
- filename: packages/backend/src/_migrations/_init-db/1603812391580-pr-env-create-database.ts
checksum: a2625bd65f7e0ffc0e0d69b98266295231c1a5f6ff6938f89258cf7d7773ff49
checksum: 99133de99ba8a6760310d62b686e25ec978fdbb0d658b5e18d06f387f366ed7e
- filename: packages/backend/src/modules/portail-usagers/controllers/portail-usagers-manager/portail-usagers-manager.controller.ts
checksum: 6cb66d899577621ac9f796b2fde88a68263b7422c3f369854d94236c15c0807f
- filename: packages/backend/src/stats/services/publicStats.service.ts
Expand Down
Binary file modified _scripts/db/dumps/domifa_test.postgres.custom.gz
Binary file not shown.
48 changes: 48 additions & 0 deletions packages/backend/src/_migrations/1721817064651-auto-migration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { MigrationInterface, QueryRunner } from "typeorm";
import { domifaConfig } from "../config";

export class AutoMigration1721817064651 implements MigrationInterface {
name = "AutoMigration1721817064651";

public async up(queryRunner: QueryRunner): Promise<void> {
if (
domifaConfig().envId === "prod" ||
domifaConfig().envId === "preprod" ||
domifaConfig().envId === "local"
) {
await queryRunner.query(
`DROP INDEX IF EXISTS "public"."IDX_9643302335674f651c0e867235"`
);
await queryRunner.query(
`DROP INDEX IF EXISTS "public"."IDX_2877f8c3f6cbddc785bf938d0a"`
);
await queryRunner.query(
`DROP INDEX IF EXISTS "public"."IDX_bf49c177bbacd36423531ecc07"`
);
await queryRunner.query(
`DROP INDEX IF EXISTS "public"."IDX_c2fa002e6f45fe1ca6c7f23496"`
);
}
}

public async down(queryRunner: QueryRunner): Promise<void> {
if (
domifaConfig().envId === "prod" ||
domifaConfig().envId === "preprod" ||
domifaConfig().envId === "local"
) {
await queryRunner.query(
`CREATE INDEX "IDX_c2fa002e6f45fe1ca6c7f23496" ON "usager_options_history" ("userId") `
);
await queryRunner.query(
`CREATE INDEX "IDX_bf49c177bbacd36423531ecc07" ON "structure" ("departmentName") `
);
await queryRunner.query(
`CREATE INDEX "IDX_2877f8c3f6cbddc785bf938d0a" ON "structure" ("regionName") `
);
await queryRunner.query(
`CREATE INDEX "IDX_9643302335674f651c0e867235" ON "app_log" ("userId") `
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ async function createTables(queryRunner: QueryRunner) {
"action" text NOT NULL,
CONSTRAINT "PK_69f8faf72fa4038748e4e3f3fbe" PRIMARY KEY (uuid)
);
CREATE INDEX "IDX_9643302335674f651c0e867235" ON public.app_log USING btree ("userId");
-- public.contact_support definition
Expand Down Expand Up @@ -202,12 +201,10 @@ async function createTables(queryRunner: QueryRunner) {
CONSTRAINT "UQ_90ac7986e769d602d218075215c" UNIQUE (id),
CONSTRAINT "UQ_b36e92e49b2a68f8fea64ec8d5b" UNIQUE (email)
);
CREATE INDEX "IDX_2877f8c3f6cbddc785bf938d0a" ON public.structure USING btree ("regionName");
CREATE INDEX "IDX_30c4985e1148ec42ad6122f0ff" ON public.structure USING btree ("structureType");
CREATE INDEX "IDX_62204f14a6d17cad41d419d150" ON public.structure USING btree ("codePostal");
CREATE INDEX "IDX_90ac7986e769d602d218075215" ON public.structure USING btree (id);
CREATE INDEX "IDX_b36e92e49b2a68f8fea64ec8d5" ON public.structure USING btree (email);
CREATE INDEX "IDX_bf49c177bbacd36423531ecc07" ON public.structure USING btree ("departmentName");
CREATE INDEX "IDX_e848a2cfbd611ec5edc18074e2" ON public.structure USING btree (region);
CREATE INDEX "IDX_fa4dea9a1ff8deb8fcf47c451e" ON public.structure USING btree (departement);
Expand Down Expand Up @@ -386,7 +383,7 @@ async function createTables(queryRunner: QueryRunner) {
);
CREATE INDEX "IDX_a44d882d224e368efdee8eb8c8" ON public.usager USING btree ("structureId");
CREATE INDEX "IDX_b4d09870ec6cad2d2d98b7cc3a" ON public.usager USING btree (migrated);
CREATE INDEX idx_usager_statut ON public.usager USING btree ("structureId", "statut");
CREATE INDEX idx_usager_statut ON public.usager USING btree ("structureId", statut);
-- public.usager_docs definition
Expand Down Expand Up @@ -558,7 +555,6 @@ async function createTables(queryRunner: QueryRunner) {
);
CREATE INDEX "IDX_3cb5af09bf7cd68d7070dbc896" ON public.usager_options_history USING btree ("usagerUUID");
CREATE INDEX "IDX_b509fe905bf502e510cda57080" ON public.usager_options_history USING btree ("structureId");
CREATE INDEX "IDX_c2fa002e6f45fe1ca6c7f23496" ON public.usager_options_history USING btree ("userId");
-- public.user_structure definition
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Column, Entity, Index } from "typeorm";
import { Column, Entity } from "typeorm";
import { AppLog, LogAction } from "../../../_common/model";
import { AppTypeormTable } from "../_core/AppTypeormTable.typeorm";

Expand All @@ -7,7 +7,6 @@ export class AppLogTable
extends AppTypeormTable<AppLogTable>
implements AppLog
{
@Index()
@Column({ type: "integer" })
public userId: number;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,9 @@ export class StructureTable
@Column({ type: "text", nullable: false })
region: string;

@Index()
@Column({ type: "text", nullable: true })
departmentName: string;

@Index()
@Column({ type: "text", nullable: true })
regionName: string;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export class UsagerOptionsHistoryTable
@JoinColumn({ name: "usagerUUID", referencedColumnName: "uuid" })
public usagerUUID: string;

@Index()
@Column({ type: "integer", nullable: true })
public userId: number;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { UsagerTable } from "../../../entities";
import { Usager } from "@domifa/common";

export const USAGER_LIGHT_ATTRIBUTES: (keyof UsagerTable)[] = [
export const USAGER_LIGHT_ATTRIBUTES: (keyof Usager)[] = [
"uuid",
"ref",
"customRef",
Expand Down
39 changes: 18 additions & 21 deletions packages/backend/src/usagers/controllers/usagers.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import { Usager, ETAPE_DOCUMENTS, CerfaDocType } from "@domifa/common";
import { UsagerHistoryStateService } from "../services/usagerHistoryState.service";
import { domifaConfig } from "../../config";
import { FileManagerService } from "../../util/file-manager/file-manager.service";
import { Not } from "typeorm";

@Controller("usagers")
@ApiTags("usagers")
Expand All @@ -78,35 +79,31 @@ export class UsagersController {
chargerTousRadies: boolean,
@CurrentUser() user: UserStructureAuthenticated
) {
const usagersNonRadies = await usagerRepository
.createQueryBuilder()
.select(joinSelectFields(USAGER_LIGHT_ATTRIBUTES))
.where(`"structureId" = :structureId and statut != :statut`, {
statut: "RADIE",
const usagersNonRadies = await usagerRepository.find({
where: {
statut: Not("RADIE"),
structureId: user.structureId,
})
.getRawMany();
},
select: USAGER_LIGHT_ATTRIBUTES,
});

const usagersRadiesFirsts = await usagerRepository
.createQueryBuilder()
.select(joinSelectFields(USAGER_LIGHT_ATTRIBUTES))
.where(`"structureId" = :structureId and statut = :statut`, {
const usagersRadiesFirsts = await usagerRepository.find({
where: {
statut: "RADIE",
structureId: user.structureId,
})
.limit(chargerTousRadies ? undefined : 60)
.orderBy({ "decision->>'dateFin'": "DESC" })
.getRawMany();
},
select: USAGER_LIGHT_ATTRIBUTES,
take: chargerTousRadies ? undefined : 60,
});

const usagersRadiesTotalCount = chargerTousRadies
? usagersRadiesFirsts.length
: await usagerRepository
.createQueryBuilder()
.where(`"structureId" = :structureId and statut = :statut`, {
: await usagerRepository.count({
where: {
statut: "RADIE",
structureId: user.structureId,
})
.getCount();
},
});

return {
usagersNonRadies,
Expand All @@ -131,7 +128,7 @@ export class UsagersController {
.createQueryBuilder()
.select(joinSelectFields(USAGER_LIGHT_ATTRIBUTES))
.where(
`"structureId" = :structureId and statut = :statut and LOWER(coalesce("nom", '') || ' ' || coalesce("prenom", '')) LIKE :search`,
`"structureId" = :structureId and statut = :statut and LOWER("nom"|| ' ' || "prenom") LIKE :search`,
{
statut: "RADIE",
structureId: user.structureId,
Expand Down

0 comments on commit b2c461a

Please sign in to comment.