Skip to content

Commit 0307304

Browse files
authored
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. <img width="2553" alt="Screenshot 2025-02-19 at 15 08 16" src="https://github.com/user-attachments/assets/b00e856c-e040-4f05-9f15-41fb8d299387" />
1 parent 508b948 commit 0307304

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

.changeset/sixty-kangaroos-accept.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@medusajs/dashboard": patch
3+
---
4+
5+
fix(dashboard): Prevent overfetching data

packages/admin/dashboard/src/hooks/table/query/use-product-table-query.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ type UseProductTableQueryProps = {
66
pageSize?: number
77
}
88

9+
const DEFAULT_FIELDS =
10+
"id,title,handle,status,*collection,*sales_channels,variants.id"
11+
912
export const useProductTableQuery = ({
1013
prefix,
1114
pageSize = 20,
@@ -58,6 +61,7 @@ export const useProductTableQuery = ({
5861
type_id: type_id?.split(","),
5962
status: status?.split(",") as HttpTypes.AdminProductStatus[],
6063
q,
64+
fields: DEFAULT_FIELDS,
6165
}
6266

6367
return {

packages/admin/dashboard/src/routes/products/product-detail/components/product-variant-section/product-variant-section.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ export const ProductVariantSection = ({
7575
: undefined,
7676
created_at: created_at ? JSON.parse(created_at) : undefined,
7777
updated_at: updated_at ? JSON.parse(updated_at) : undefined,
78-
fields: "*inventory_items.inventory.location_levels,+inventory_quantity",
78+
fields:
79+
"title,sku,*options,created_at,updated_at,*inventory_items.inventory.location_levels,inventory_quantity",
7980
},
8081
{
8182
placeholderData: keepPreviousData,

packages/admin/dashboard/src/routes/products/product-prices/product-prices.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ import { PricingEdit } from "./pricing-edit"
77
export const ProductPrices = () => {
88
const { id, variant_id } = useParams()
99

10-
const { product, isLoading, isError, error } = useProduct(id!, {
11-
fields: "+variants,+variants.prices",
12-
})
10+
const { product, isLoading, isError, error } = useProduct(id!)
1311

1412
if (isError) {
1513
throw error

0 commit comments

Comments
 (0)