fix(dashboard,medusa,types): improve performance for price list prices retrieval (#14138)

## Summary

**What** — What changes are introduced in this PR?

Price lists prices didn't have a dedicated method to query them and instead, relied on being returned as part of price lists. This, however, introduces optimization issues that for price lists with many prices, could cause crashes. The reason being that relations are not paginated and thus, all prices linked to the price list would be returned.

This PR aims to solve this by introducing a dedicated endpoint and avoiding returning the `prices` as part of price lists by default. The idea being that it is up to the user to explicitly express this, which, for small price lists no issues will arise, but for bigger ones, they will easily recognize the performance impact.

**Why** — Why are these changes relevant or necessary?  

Users with large enough price lists would have serious performance issues or even crashes when querying the `/admin/price-lists` endpoints. This is also true when navigating to the price list section of the Admin UI since it queries this same endpoints.

**How** — How have these changes been implemented?

- Removed the `prices` relation to be part of the default fields returned by the `/admin/price-lists/` endpoints. User may still request it by passing it in `fields` query param.
- Added new `/admin/price-lists/[id]/prices` GET endpoint to be able to retrieve a price list prices with pagination.

**Testing** — How have these changes been tested, or how can the reviewer test the feature?

Integration tests.

---

## Examples

Provide examples or code snippets that demonstrate how this feature works, or how it can be used in practice.  
This helps with documentation and ensures maintainers can quickly understand and verify the change.

```ts
// Example usage
```

---

## Checklist

Please ensure the following before requesting a review:

- [x] I have added a **changeset** for this PR
    - Every non-breaking change should be marked as a **patch**
    - To add a changeset, run `yarn changeset` and follow the prompts
- [x] The changes are covered by relevant **tests**
- [x] I have verified the code works as intended locally
- [x] I have linked the related issue(s) if applicable

---

## Additional Context

The current state of the PR fixes the issue on the price list list and detail component. It still doesn't solve the issue for the following screens: Edit Prices & Add Prices

All the prices are still retrieved from the `/admin/price-lists/` endpoint for these. I want first some feedback before changing it to the new endpoint, since the current DataGrid implementation doesn't support pagination and it seems we are passing a default limit for the products to show there, an arbitrarily large number 9999 and there is also a TODO comment of changing that.

This previous point, though, could be implemented in a later PR, so we can already fix the issue in the price list list and detail pages, so at least for large price lists these screens don't explode and smaller price lists can still have its product prices edited, while only large ones will explode when trying to perform this action. @adrien2p @fPolic thoughts?

closes ENTSUP-265, CORE-1239
This commit is contained in:
Nicolas Gorga
2025-12-11 10:13:08 -03:00
committed by GitHub
parent 237b472e73
commit 70929ecac3
17 changed files with 353 additions and 147 deletions

View File

@@ -19,24 +19,24 @@ export class PriceList {
* This method retrieves a price list. It sends a request to the
* [Get Price List](https://docs.medusajs.com/v2/api/admin#price-lists_getpricelistsid)
* API route.
*
*
* @param id - The price list's ID.
* @param query - Configure the fields to retrieve in the price list.
* @param headers - Headers to pass in the request
* @returns The price list's details.
*
*
* @example
* To retrieve a price list by its ID:
*
*
* ```ts
* sdk.admin.priceList.retrieve("plist_123")
* .then(({ price_list }) => {
* console.log(price_list)
* })
* ```
*
*
* To specify the fields and relations to retrieve:
*
*
* ```ts
* sdk.admin.priceList.retrieve("plist_123", {
* fields: "id,*prices"
@@ -45,7 +45,7 @@ export class PriceList {
* console.log(price_list)
* })
* ```
*
*
* Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/v2/api/store#select-fields-and-relations).
*/
async retrieve(
@@ -64,27 +64,27 @@ export class PriceList {
}
/**
* This method retrieves a paginated list of price lists. It sends a request to the
* This method retrieves a paginated list of price lists. It sends a request to the
* [List Price Lists](https://docs.medusajs.com/v2/api/admin#price-lists_getpricelists) API route.
*
*
* @param query - Filters and pagination configurations.
* @param headers - Headers to pass in the request.
* @returns The paginated list of price lists.
*
*
* @example
* To retrieve the list of price lists:
*
*
* ```ts
* sdk.admin.priceList.list()
* .then(({ price_lists, count, limit, offset }) => {
* console.log(price_lists)
* })
* ```
*
*
* To configure the pagination, pass the `limit` and `offset` query parameters.
*
*
* For example, to retrieve only 10 items and skip 10 items:
*
*
* ```ts
* sdk.admin.priceList.list({
* limit: 10,
@@ -94,10 +94,10 @@ export class PriceList {
* console.log(price_lists)
* })
* ```
*
*
* Using the `fields` query parameter, you can specify the fields and relations to retrieve
* in each price list:
*
*
* ```ts
* sdk.admin.priceList.list({
* fields: "id,*prices"
@@ -106,7 +106,7 @@ export class PriceList {
* console.log(price_lists)
* })
* ```
*
*
* Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/v2/api/store#select-fields-and-relations).
*/
async list(
@@ -127,12 +127,12 @@ export class PriceList {
* This method creates a price list. It sends a request to the
* [Create Price List](https://docs.medusajs.com/v2/api/admin#price-lists_postpricelists)
* API route.
*
*
* @param body - The details of the price list to create.
* @param query - Configure the fields to retrieve in the price list.
* @param headers - Headers to pass in the request
* @returns The price list's details.
*
*
* @example
* sdk.admin.priceList.create({
* title: "My Price List",
@@ -170,16 +170,16 @@ export class PriceList {
}
/**
* This method updates a price list. It sends a request to the
* This method updates a price list. It sends a request to the
* [Update Price List](https://docs.medusajs.com/v2/api/admin#price-lists_postpricelistsid)
* API route.
*
*
* @param id - The price list's ID.
* @param body - The data to update in the price list.
* @param query - Configure the fields to retrieve in the price list.
* @param headers - Headers to pass in the request
* @returns The price list's details.
*
*
* @example
* sdk.admin.priceList.update("plist_123", {
* title: "My Price List",
@@ -209,11 +209,11 @@ export class PriceList {
* This method deletes a price list. It sends a request to the
* [Delete Price List](https://docs.medusajs.com/v2/api/admin#price-lists_deletepricelistsid)
* API route.
*
*
* @param id - The price list's ID.
* @param headers - Headers to pass in the request
* @returns The deletion's details.
*
*
* @example
* sdk.admin.priceList.delete("plist_123")
* .then(({ deleted }) => {
@@ -234,13 +234,13 @@ export class PriceList {
* This method manages the prices of a price list to create, update, or delete them.
* It sends a request to the [Manage Prices](https://docs.medusajs.com/v2/api/admin#price-lists_postpricelistsidpricesbatch)
* API route.
*
*
* @param id - The price list's ID.
* @param body - The prices to create, update, or delete.
* @param query - Configure the fields to retrieve in the price list.
* @param headers - Headers to pass in the request
* @returns The price list's details.
*
*
* @example
* sdk.admin.priceList.batchPrices("plist_123", {
* create: [{
@@ -279,17 +279,47 @@ export class PriceList {
)
}
/**
* This method retrieves the prices of a price list. It sends a request to the
* [Get Prices](https://docs.medusajs.com/v2/api/admin#price-lists_getpricelistsidprices)
* API route.
*
* @param id - The price list's ID.
* @param query - Configure the fields to retrieve in the price list.
* @param headers - Headers to pass in the request
* @returns The price list's prices.
*
* @example
* sdk.admin.priceList.prices("plist_123")
* .then(({ prices }) => {
* console.log(prices)
* })
*/
async prices(
id: string,
query?: HttpTypes.AdminPriceListPriceListParams,
headers?: ClientHeaders
) {
return this.client.fetch<HttpTypes.AdminPriceListPriceListResponse>(
`/admin/price-lists/${id}/prices`,
{
method: "GET",
headers,
query,
}
)
}
/**
* This method removes products from a price list. It sends a request to the
* [Remove Product](https://docs.medusajs.com/v2/api/admin#price-lists_postpricelistsidproducts)
* API route.
*
*
* @param id - The price list's ID.
* @param body - The details of the products to remove.
* @param query - Configure the fields to retrieve in the price list.
* @param headers - Headers to pass in the request
* @returns The price list's details.
*
*
* @example
* sdk.admin.priceList.linkProducts("plist_123", {
* remove: ["prod_123"]

View File

@@ -32,3 +32,7 @@ export interface AdminPriceListListParams
}
export interface AdminPriceListParams extends SelectParams {}
export interface AdminPriceListPriceListParams
extends FindParams,
BaseFilterable<AdminPriceListPriceListParams> {}

View File

@@ -38,3 +38,8 @@ export interface AdminPriceListBatchResponse {
deleted: boolean
}
}
export interface AdminPriceListPriceListResponse
extends PaginatedResponse<{
prices: AdminPrice[]
}> {}