From 0307304dc679bc1533e5826e0bb726f7895a0615 Mon Sep 17 00:00:00 2001 From: Adrien de Peretti Date: Wed, 19 Feb 2025 15:26:22 +0100 Subject: [PATCH] fix(dashboard): Prevent overfetching data (#11532) **What** Currently, the dashboard is fetching way more data than needed to display the products. This can lead to issues for complex catalog. this pr aim to reduce the data to be fetched to exactly what is needed. Screenshot 2025-02-19 at 15 08 16 --- .changeset/sixty-kangaroos-accept.md | 5 +++++ .../src/hooks/table/query/use-product-table-query.tsx | 4 ++++ .../product-variant-section/product-variant-section.tsx | 3 ++- .../src/routes/products/product-prices/product-prices.tsx | 4 +--- 4 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 .changeset/sixty-kangaroos-accept.md diff --git a/.changeset/sixty-kangaroos-accept.md b/.changeset/sixty-kangaroos-accept.md new file mode 100644 index 0000000000..0a47e3f000 --- /dev/null +++ b/.changeset/sixty-kangaroos-accept.md @@ -0,0 +1,5 @@ +--- +"@medusajs/dashboard": patch +--- + +fix(dashboard): Prevent overfetching data diff --git a/packages/admin/dashboard/src/hooks/table/query/use-product-table-query.tsx b/packages/admin/dashboard/src/hooks/table/query/use-product-table-query.tsx index b747efc0c6..77cd3cf5cf 100644 --- a/packages/admin/dashboard/src/hooks/table/query/use-product-table-query.tsx +++ b/packages/admin/dashboard/src/hooks/table/query/use-product-table-query.tsx @@ -6,6 +6,9 @@ type UseProductTableQueryProps = { pageSize?: number } +const DEFAULT_FIELDS = + "id,title,handle,status,*collection,*sales_channels,variants.id" + export const useProductTableQuery = ({ prefix, pageSize = 20, @@ -58,6 +61,7 @@ export const useProductTableQuery = ({ type_id: type_id?.split(","), status: status?.split(",") as HttpTypes.AdminProductStatus[], q, + fields: DEFAULT_FIELDS, } return { diff --git a/packages/admin/dashboard/src/routes/products/product-detail/components/product-variant-section/product-variant-section.tsx b/packages/admin/dashboard/src/routes/products/product-detail/components/product-variant-section/product-variant-section.tsx index fad49a3bf0..d8d56409eb 100644 --- a/packages/admin/dashboard/src/routes/products/product-detail/components/product-variant-section/product-variant-section.tsx +++ b/packages/admin/dashboard/src/routes/products/product-detail/components/product-variant-section/product-variant-section.tsx @@ -75,7 +75,8 @@ export const ProductVariantSection = ({ : undefined, created_at: created_at ? JSON.parse(created_at) : undefined, updated_at: updated_at ? JSON.parse(updated_at) : undefined, - fields: "*inventory_items.inventory.location_levels,+inventory_quantity", + fields: + "title,sku,*options,created_at,updated_at,*inventory_items.inventory.location_levels,inventory_quantity", }, { placeholderData: keepPreviousData, diff --git a/packages/admin/dashboard/src/routes/products/product-prices/product-prices.tsx b/packages/admin/dashboard/src/routes/products/product-prices/product-prices.tsx index 85efaac295..90ea3d888d 100644 --- a/packages/admin/dashboard/src/routes/products/product-prices/product-prices.tsx +++ b/packages/admin/dashboard/src/routes/products/product-prices/product-prices.tsx @@ -7,9 +7,7 @@ import { PricingEdit } from "./pricing-edit" export const ProductPrices = () => { const { id, variant_id } = useParams() - const { product, isLoading, isError, error } = useProduct(id!, { - fields: "+variants,+variants.prices", - }) + const { product, isLoading, isError, error } = useProduct(id!) if (isError) { throw error