chore(product): revamp upsertWithReplace and Remove its usage from product creation (#11585)
**What** - Move create product to use native create by structuring the data appropriately, it means no more `upsertWithReplace` being very poorly performant and got 20x better performances on staging - Improvements in `upsertWithReplace` to still get performance boost for places that still relies on it. Mostly bulking the operations when possible Co-authored-by: Carlos R. L. Rodrigues <37986729+carlos-r-l-rodrigues@users.noreply.github.com>
This commit is contained in:
co-authored by
Carlos R. L. Rodrigues
parent
a35c9ed741
commit
eeebb35758
+3
-3
@@ -48,11 +48,11 @@ export const buildProductAndRelationsData = ({
|
||||
images,
|
||||
status,
|
||||
type_id,
|
||||
tags,
|
||||
tag_ids,
|
||||
options,
|
||||
variants,
|
||||
collection_id,
|
||||
}: Partial<ProductTypes.CreateProductDTO> & { tags: { value: string }[] }) => {
|
||||
}: Partial<ProductTypes.CreateProductDTO>) => {
|
||||
const defaultOptionTitle = "test-option"
|
||||
const defaultOptionValue = "test-value"
|
||||
|
||||
@@ -66,7 +66,7 @@ export const buildProductAndRelationsData = ({
|
||||
status: status ?? ProductStatus.PUBLISHED,
|
||||
images: (images ?? []) as ProductImage[],
|
||||
type_id,
|
||||
tags: tags ?? [{ value: "tag-1" }],
|
||||
tag_ids,
|
||||
collection_id,
|
||||
options: options ?? [
|
||||
{
|
||||
|
||||
+11
-5
@@ -30,7 +30,7 @@ import {
|
||||
createTypes,
|
||||
} from "../../__fixtures__/product"
|
||||
|
||||
jest.setTimeout(300000)
|
||||
jest.setTimeout(3000000)
|
||||
|
||||
moduleIntegrationTestRunner<IProductModuleService>({
|
||||
moduleName: Modules.PRODUCT,
|
||||
@@ -181,6 +181,7 @@ moduleIntegrationTestRunner<IProductModuleService>({
|
||||
})
|
||||
|
||||
it("should update a product and upsert relations that are not created yet", async () => {
|
||||
const tags = await service.createProductTags([{ value: "tag-1" }])
|
||||
const data = buildProductAndRelationsData({
|
||||
images,
|
||||
thumbnail: images[0].url,
|
||||
@@ -190,6 +191,7 @@ moduleIntegrationTestRunner<IProductModuleService>({
|
||||
values: ["val-1", "val-2"],
|
||||
},
|
||||
],
|
||||
tag_ids: [tags[0].id],
|
||||
})
|
||||
|
||||
const variantTitle = data.variants[0].title
|
||||
@@ -217,7 +219,7 @@ moduleIntegrationTestRunner<IProductModuleService>({
|
||||
productBefore.options = data.options
|
||||
productBefore.images = data.images
|
||||
productBefore.thumbnail = data.thumbnail
|
||||
productBefore.tags = data.tags
|
||||
productBefore.tag_ids = data.tag_ids
|
||||
const updatedProducts = await service.upsertProducts([productBefore])
|
||||
expect(updatedProducts).toHaveLength(1)
|
||||
|
||||
@@ -273,7 +275,7 @@ moduleIntegrationTestRunner<IProductModuleService>({
|
||||
tags: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
value: productBefore.tags?.[0].value,
|
||||
value: tags[0].value,
|
||||
}),
|
||||
]),
|
||||
variants: expect.arrayContaining([
|
||||
@@ -856,9 +858,11 @@ moduleIntegrationTestRunner<IProductModuleService>({
|
||||
describe("create", function () {
|
||||
let images = [{ url: "image-1" }]
|
||||
it("should create a product", async () => {
|
||||
const tags = await service.createProductTags([{ value: "tag-1" }])
|
||||
const data = buildProductAndRelationsData({
|
||||
images,
|
||||
thumbnail: images[0].url,
|
||||
tag_ids: [tags[0].id],
|
||||
})
|
||||
|
||||
const productsCreated = await service.createProducts([data])
|
||||
@@ -917,7 +921,7 @@ moduleIntegrationTestRunner<IProductModuleService>({
|
||||
tags: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
value: data.tags[0].value,
|
||||
value: tags[0].value,
|
||||
}),
|
||||
]),
|
||||
variants: expect.arrayContaining([
|
||||
@@ -1164,15 +1168,17 @@ moduleIntegrationTestRunner<IProductModuleService>({
|
||||
productCollectionOne = collections[0]
|
||||
productCollectionTwo = collections[1]
|
||||
|
||||
const tags = await service.createProductTags([{ value: "tag-1" }])
|
||||
|
||||
const resp = await service.createProducts([
|
||||
buildProductAndRelationsData({
|
||||
collection_id: productCollectionOne.id,
|
||||
options: [{ title: "size", values: ["large", "small"] }],
|
||||
variants: [{ title: "variant 1", options: { size: "small" } }],
|
||||
tag_ids: [tags[0].id],
|
||||
}),
|
||||
buildProductAndRelationsData({
|
||||
collection_id: productCollectionTwo.id,
|
||||
tags: [],
|
||||
}),
|
||||
])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user