Skip to content

Commit

Permalink
fix: prroblèmes de lenteur, merci Arnest ref #175
Browse files Browse the repository at this point in the history
  • Loading branch information
pprev94 committed Nov 28, 2023
1 parent 277ccc8 commit cef5ec3
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 8 deletions.
42 changes: 38 additions & 4 deletions assets/pages/datasheet/DatasheetView/DatasheetView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,26 @@ const DatasheetView: FC<DatasheetViewProps> = ({ datastoreId, datasheetName }) =
form.append("file", upload);
return api.annexe.addThumbnail(datastoreId, form);
},
onSuccess: () => {
onSuccess: (response) => {
addThumbnailModal.close();
queryClient.refetchQueries({ queryKey: RQKeys.datastore_datasheet(datastoreId, datasheetName) });

// Mise à jour du contenu de la réponse de datasheetQuery
queryClient.setQueryData<DatasheetDetailed>(RQKeys.datastore_datasheet(datastoreId, datasheetName), (datasheet) => {
if (datasheet) {
datasheet.thumbnail = response;
}
return datasheet;
});

// Mise à jour du contenu de la réponse de datasheetListQuery
queryClient.setQueryData<Datasheet[]>(RQKeys.datastore_datasheet_list(datastoreId), (datasheetList = []) => {
return datasheetList.map((datasheet) => {
if (datasheet.name === datasheetName) {
datasheet.thumbnail = response;
}
return datasheet;
});
});
},
onSettled: () => {
reset();
Expand All @@ -130,7 +147,24 @@ const DatasheetView: FC<DatasheetViewProps> = ({ datastoreId, datasheetName }) =
},
onSuccess: () => {
addThumbnailModal.close();
queryClient.refetchQueries({ queryKey: RQKeys.datastore_datasheet(datastoreId, datasheetName) });

// mise à jour du contenu de la réponse de datasheetQuery
queryClient.setQueryData<DatasheetDetailed>(RQKeys.datastore_datasheet(datastoreId, datasheetName), (datasheet) => {
if (datasheet) {
datasheet.thumbnail = undefined;
}
return datasheet;
});

// mise à jour du contenu de la réponse de datasheetListQuery
queryClient.setQueryData<Datasheet[]>(RQKeys.datastore_datasheet_list(datastoreId), (datasheetList = []) => {
return datasheetList.map((datasheet) => {
if (datasheet.name === datasheetName) {
datasheet.thumbnail = undefined;
}
return datasheet;
});
});
},
onSettled: () => {
reset();
Expand Down Expand Up @@ -250,7 +284,7 @@ const DatasheetView: FC<DatasheetViewProps> = ({ datastoreId, datasheetName }) =
onClick={handleChooseThumbnail}
nativeButtonProps={{ "aria-label": t("button.title"), title: t("button.title") }}
>
<img src={thumbnailUrl === "" ? defaultImgUrl : thumbnailUrl} width={"128px"} />
<img src={thumbnailUrl === "" ? defaultImgUrl : thumbnailUrl} width="128px" height="128px" />
</Button>
</div>
<div className={fr.cx("fr-col")}>
Expand Down
3 changes: 1 addition & 2 deletions assets/types/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,14 @@ export type Datasheet = {
date: string;
categories: string[];
nb_publications: number;
thumbnail: AnnexDetailResponseDto & { url: string };
thumbnail?: AnnexDetailResponseDto & { url: string };
};

export type DatasheetDetailed = Datasheet & {
vector_db_list: VectorDb[] | undefined;
pyramid_list: Pyramid[] | undefined;
upload_list: Upload[] | undefined;
service_list: Service[] | undefined;
thumbnail: AnnexDetailResponseDto & { url: string };
};

/** stored_data (donnée stockée) */
Expand Down
3 changes: 1 addition & 2 deletions src/Controller/Api/DatasheetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,7 @@ public function delete(string $datastoreId, string $datasheetName): Response
}

// TODO : autres données à supprimer

// Suppression des annexes
// Suppression des annexes
$annexes = $this->entrepotApiService->annexe->getAll($datastoreId, null, null, ["datasheet_name=$datasheetName"]);
foreach ($annexes as $annexe) {
$this->entrepotApiService->annexe->remove($datastoreId, $annexe['_id']);
Expand Down

0 comments on commit cef5ec3

Please sign in to comment.