Skip to content

Commit

Permalink
change getConventions query structure for better query stats
Browse files Browse the repository at this point in the history
  • Loading branch information
enguerranws authored and JeromeBu committed Sep 20, 2024
1 parent 36a6146 commit 4a8e2a1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,12 @@ describe("Pg implementation of ConventionQueries", () => {
describe("PG implementation of method getConventionsByFilters", () => {
const agencyId = "bbbbbc15-9c0a-1aaa-aa6d-6aa9ad38aaff";
const agency = AgencyDtoBuilder.create().withId(agencyId).build();
const siret1 = "11110000111100";
const siret2 = "22220000222200";
const siret3 = "33330000333300";

const conventionCancelledAndDateStart20230327 = new ConventionDtoBuilder()
.withSiret(siret1)
.withId("bbbbbc15-9c0a-1aaa-aa6d-6aa9ad38aa01")
.withDateStart(new Date("2023-03-27").toISOString())
.withDateEnd(new Date("2023-03-28").toISOString())
Expand All @@ -346,6 +351,7 @@ describe("Pg implementation of ConventionQueries", () => {
.build();

const conventionDraftAndDateStart20230330 = new ConventionDtoBuilder()
.withSiret(siret3)
.withId("bbbbbc15-9c0a-1aaa-aa6d-6aa9ad38aa02")
.withDateSubmission(new Date("2023-03-05").toISOString())
.withDateStart(new Date("2023-03-30").toISOString())
Expand All @@ -356,6 +362,7 @@ describe("Pg implementation of ConventionQueries", () => {
.build();

const firstValidatedConvention = new ConventionDtoBuilder()
.withSiret(siret1)
.withId("bbbbbc15-9c0a-1aaa-aa6d-6aa9ad38aa03")
.withDateSubmission(new Date("2024-06-20").toISOString())
.withDateStart(new Date("2024-07-01").toISOString())
Expand All @@ -368,6 +375,7 @@ describe("Pg implementation of ConventionQueries", () => {
.build();

const secondValidatedConvention = new ConventionDtoBuilder()
.withSiret(siret2)
.withId("bbbbbc15-9c0a-1aaa-aa6d-6aa9ad38aa04")
.withDateSubmission(new Date("2024-06-21").toISOString())
.withDateStart(new Date("2024-07-02").toISOString())
Expand Down Expand Up @@ -523,6 +531,21 @@ describe("Pg implementation of ConventionQueries", () => {
firstValidatedConvention,
]);
});

it("getConventionsByFilters with some sirets", async () => {
const resultAll = await conventionQueries.getConventions({
filters: {
withSirets: [siret1, siret2],
},
sortBy: "dateStart",
});

expectToEqual(resultAll, [
secondValidatedConvention,
firstValidatedConvention,
conventionCancelledAndDateStart20230327,
]);
});
});

describe("findSimilarConventions", () => {
Expand Down
3 changes: 2 additions & 1 deletion back/src/domains/convention/adapters/PgConventionQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
ConventionStatus,
DateRange,
FindSimilarConventionsParams,
SiretDto,
conventionReadSchema,
conventionSchema,
pipeWithValue,
Expand Down Expand Up @@ -279,7 +280,7 @@ const addFiltersToBuilder =

const addWithSiretsIfNeeded: AddToBuilder = (b) =>
withSirets && withSirets.length > 0
? b.where("conventions.siret", "in", withSirets)
? b.where("conventions.siret", "=", sql<SiretDto>`ANY(${withSirets})`)
: b;

return pipeWithValue(
Expand Down

0 comments on commit 4a8e2a1

Please sign in to comment.