Skip to content

Commit

Permalink
front: fix unnecessary calls to simulation_summary by making postV2Tr…
Browse files Browse the repository at this point in the history
…ainScheduleProjectPath a query.

Codegen makes all the POSTs mutations by default. This one is only a POST to have a body, but is not creating/modifying anything in the DB.
No reason to be considered a mutation on the frontend.

As a query it doesn't have an invalidatesTags array anymore and prevents the unnecessary calls to simulation_summary.
  • Loading branch information
anisometropie committed Jul 18, 2024
1 parent a9a3ddc commit 766b2fa
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions front/src/applications/stdcm/hooks/useStdcmResults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const useStdcmResults = (
const [postPathProperties] =
osrdEditoastApi.endpoints.postV2InfraByInfraIdPathProperties.useMutation();
const [projectTrainSchedules] =
osrdEditoastApi.endpoints.postV2TrainScheduleProjectPath.useMutation();
osrdEditoastApi.endpoints.postV2TrainScheduleProjectPath.useLazyQuery();

const { data: otherSelectedTrainSchedule } =
osrdEditoastApi.endpoints.getV2TrainScheduleById.useQuery(
Expand Down Expand Up @@ -176,7 +176,7 @@ const useStdcmResults = (
stdcmResponse.rollingStock.length
);
}
}, [stdcmResponse]);
}, [stdcmResponse, infraId, timetable, projectTrainSchedules]);

if (!infraId || !stdcmResponse || !selectedTrainSchedule) return null;

Expand Down
4 changes: 2 additions & 2 deletions front/src/common/api/generatedEditoastApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ const injectedRtkApi = api
}),
invalidatesTags: ['timetablev2', 'train_schedulev2'],
}),
postV2TrainScheduleProjectPath: build.mutation<
postV2TrainScheduleProjectPath: build.query<
PostV2TrainScheduleProjectPathApiResponse,
PostV2TrainScheduleProjectPathApiArg
>({
Expand All @@ -934,7 +934,7 @@ const injectedRtkApi = api
method: 'POST',
body: queryArg.projectPathForm,
}),
invalidatesTags: ['train_schedulev2'],
providesTags: ['train_schedulev2'],
}),
postV2TrainScheduleSimulationSummary: build.query<
PostV2TrainScheduleSimulationSummaryApiResponse,
Expand Down
6 changes: 5 additions & 1 deletion front/src/config/openapi-editoast-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ const config: ConfigFile = {
tag: true,
endpointOverrides: [
{
pattern: ['postV2TrainSchedule', 'postV2TrainScheduleSimulationSummary'],
pattern: [
'postV2TrainSchedule',
'postV2TrainScheduleSimulationSummary',
'postV2TrainScheduleProjectPath',
],
type: 'query',
},
],
Expand Down

0 comments on commit 766b2fa

Please sign in to comment.