Skip to content

Commit

Permalink
perf: optimisation de requêtes page liste de données
Browse files Browse the repository at this point in the history
  • Loading branch information
ocruze committed Dec 2, 2024
1 parent 089fcf1 commit a6491a2
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 37 deletions.
19 changes: 9 additions & 10 deletions assets/@types/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import {
UserKeyDetailsResponseDtoUserKeyInfoDto,
UserKeyResponseDto,
MetadataResponseDto,
BoundingBox,
} from "./entrepot";

/** user */
Expand Down Expand Up @@ -74,19 +73,19 @@ export enum DatasheetDocumentTypeEnum {
Link = "link",
}

type PartialVectorDb = Pick<VectorDb, "name" | "description" | "type" | "visibility" | "status" | "srs" | "contact" | "size" | "last_event" | "tags"> & {
bbox?: BoundingBox;
};
// type PartialVectorDb = Pick<VectorDb, "name" | "description" | "type" | "visibility" | "status" | "srs" | "contact" | "size" | "last_event" | "tags"> & {
// bbox?: BoundingBox;
// };

type PartialPyramid = Pick<Pyramid, "name" | "description" | "type" | "visibility" | "status" | "srs" | "contact" | "size" | "last_event" | "tags"> & {
bbox?: BoundingBox;
};
// type PartialPyramid = Pick<Pyramid, "name" | "description" | "type" | "visibility" | "status" | "srs" | "contact" | "size" | "last_event" | "tags"> & {
// bbox?: BoundingBox;
// };

export type DatasheetDetailed = Datasheet & {
vector_db_list: PartialVectorDb[] | undefined;
pyramid_list: PartialPyramid[] | undefined;
vector_db_list: VectorDb[] | undefined;
pyramid_list: Pyramid[] | undefined;
upload_list: Upload[] | undefined;
// service_list: Service[] | undefined;
service_list: Service[] | undefined;
};

/** stored_data (donnée stockée) */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ const DatasheetList: FC<DatasheetListProps> = ({ datastoreId }) => {
const datasheetListQuery = useQuery({
queryKey: RQKeys.datastore_datasheet_list(datastoreId),
queryFn: ({ signal }) => api.datasheet.getList(datastoreId, { signal }),
staleTime: 30000,
refetchInterval: 30000,
staleTime: 60000,
refetchInterval: 60000,
enabled: datastoreQuery.data !== undefined,
});

Expand Down
24 changes: 8 additions & 16 deletions assets/entrepot/pages/datasheet/DatasheetView/DatasheetView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { FC } from "react";
import { createPortal } from "react-dom";
import { symToStr } from "tsafe/symToStr";

import { DatasheetDocumentTypeEnum, Service, type Datasheet, type DatasheetDetailed, type DatasheetDocument, type Metadata } from "../../../../@types/app";
import { DatasheetDocumentTypeEnum, type Datasheet, type DatasheetDetailed, type DatasheetDocument, type Metadata } from "../../../../@types/app";
import DatastoreLayout from "../../../../components/Layout/DatastoreLayout";
import LoadingIcon from "../../../../components/Utils/LoadingIcon";
import Wait from "../../../../components/Utils/Wait";
Expand Down Expand Up @@ -75,27 +75,19 @@ const DatasheetView: FC<DatasheetViewProps> = ({ datastoreId, datasheetName }) =
enabled: !datasheetDeleteMutation.isPending,
});

const datasheetServicesQuery = useQuery<Service[], CartesApiException>({
queryKey: RQKeys.datastore_datasheet_service_list(datastoreId, datasheetName),
queryFn: ({ signal }) => api.datasheet.getServices(datastoreId, datasheetName, { signal }),
enabled: !datasheetQuery.isFetching && !datasheetDeleteMutation.isPending,
staleTime: 60000,
retry: false,
});

const metadataQuery = useQuery<Metadata, CartesApiException>({
queryKey: RQKeys.datastore_metadata_by_datasheet_name(datastoreId, datasheetName),
queryFn: ({ signal }) => api.metadata.getByDatasheetName(datastoreId, datasheetName, { signal }),
enabled: !datasheetQuery.isFetching && !datasheetDeleteMutation.isPending,
enabled: !datasheetDeleteMutation.isPending,
staleTime: 60000,
retry: false,
});

const documentsListQuery = useQuery({
queryKey: RQKeys.datastore_datasheet_documents_list(datastoreId, datasheetName),
queryFn: ({ signal }) => api.datasheetDocument.getList(datastoreId, datasheetName, { signal }),
staleTime: 60000,
enabled: activeTab === DatasheetViewActiveTabEnum.Documents,
staleTime: 120000,
enabled: !datasheetDeleteMutation.isPending,
});

return (
Expand Down Expand Up @@ -179,7 +171,7 @@ const DatasheetView: FC<DatasheetViewProps> = ({ datastoreId, datasheetName }) =
tabId: DatasheetViewActiveTabEnum.Dataset,
},
{
label: t("tab_label.services", { num: datasheetServicesQuery.data?.length || 0 }),
label: t("tab_label.services", { num: datasheetQuery.data.service_list?.length || 0 }),
tabId: DatasheetViewActiveTabEnum.Services,
},
{
Expand All @@ -205,7 +197,7 @@ const DatasheetView: FC<DatasheetViewProps> = ({ datastoreId, datasheetName }) =
<ServicesListTab
datastoreId={datastoreId}
datasheet={datasheetQuery.data}
datasheet_services_list={datasheetServicesQuery.data ?? []}
datasheet_services_list={datasheetQuery.data.service_list ?? []}
/>
);

Expand Down Expand Up @@ -254,8 +246,8 @@ const DatasheetView: FC<DatasheetViewProps> = ({ datastoreId, datasheetName }) =
{datasheetQuery?.data?.pyramid_list?.length && datasheetQuery?.data?.pyramid_list.length > 0 ? (
<li>{datasheetQuery?.data?.pyramid_list.length} pyramide(s) de tuiles vectorielles</li>
) : null}
{datasheetServicesQuery.data?.length && datasheetServicesQuery.data.length > 0 ? (
<li>{datasheetServicesQuery.data.length} service(s) publié(s)</li>
{datasheetQuery.data?.service_list?.length && datasheetQuery.data.service_list.length > 0 ? (
<li>{datasheetQuery.data?.service_list.length} service(s) publié(s)</li>
) : null}
{datasheetQuery?.data?.upload_list?.length && datasheetQuery?.data?.upload_list.length > 0 ? (
<li>{datasheetQuery?.data?.upload_list.length} livraison(s)</li>
Expand Down
16 changes: 7 additions & 9 deletions src/Controller/Entrepot/DatasheetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
'/api/datastores/{datastoreId}/datasheet',
name: 'cartesgouvfr_api_datasheet_',
options: ['expose' => true],
// condition: 'request.isXmlHttpRequest()'
condition: 'request.isXmlHttpRequest()'
)]
class DatasheetController extends AbstractController implements ApiControllerInterface
{
Expand Down Expand Up @@ -91,18 +91,18 @@ public function getDatasheetList(string $datastoreId): JsonResponse
public function getDetailed(string $datastoreId, string $datasheetName): JsonResponse
{
// recherche d'entités API qui représente une fiche de données : upload, stored_data, metadata
$uploadList = $this->uploadApiService->getAll($datastoreId, [
$uploadList = $this->uploadApiService->getAllDetailed($datastoreId, [
'tags' => [
CommonTags::DATASHEET_NAME => $datasheetName,
],
'fields' => ['name', 'description', 'type', 'visibility', 'status', 'srs', 'contact', 'size', 'last_event', 'tags', 'bbox'],
// 'fields' => ['name', 'description', 'type', 'visibility', 'status', 'srs', 'contact', 'size', 'last_event', 'tags', 'bbox'],
]);

$storedDataList = $this->storedDataApiService->getAll($datastoreId, [
$storedDataList = $this->storedDataApiService->getAllDetailed($datastoreId, [
'tags' => [
CommonTags::DATASHEET_NAME => $datasheetName,
],
'fields' => ['name', 'description', 'type', 'visibility', 'status', 'srs', 'contact', 'size', 'last_event', 'tags', 'bbox'],
// 'fields' => ['name', 'description', 'type', 'visibility', 'status', 'srs', 'contact', 'size', 'last_event', 'tags', 'bbox'],
]);

$vectorDbList = array_filter($storedDataList, function ($storedData) {
Expand Down Expand Up @@ -130,9 +130,7 @@ public function getDetailed(string $datastoreId, string $datasheetName): JsonRes
$datasheet = $this->getBasicInfo($datastore, $datasheetName);

// Recherche de services (configuration et offering)
$storedDataList = array_merge($vectorDbList, $pyramidList);
// $services = $this->_getServices($datastoreId, $storedDataList);
$services = [];
$services = $this->_getServices($datastoreId, $storedDataList);

return $this->json([
...$datasheet,
Expand All @@ -146,7 +144,7 @@ public function getDetailed(string $datastoreId, string $datasheetName): JsonRes
#[Route('/{datasheetName}/services', name: 'get_services', methods: ['GET'])]
public function getServices(string $datastoreId, string $datasheetName): JsonResponse
{
$storedDataList = $this->storedDataApiService->getAllDetailed($datastoreId, [
$storedDataList = $this->storedDataApiService->getAll($datastoreId, [
'tags' => [
CommonTags::DATASHEET_NAME => $datasheetName,
],
Expand Down

0 comments on commit a6491a2

Please sign in to comment.