feat(medusa): Performance improvements of Carts domain (#2648)

**What**

I have created a new method on the cart service which is `addLineItems`, allowing a user to add one or multiple items in an optimized way. Also updated the `generate` method from the line item service which now also accept a object data or a collection of data which. Various places have been optimized and cache support has been added to the price selection strategy.

The overall optimization allows to reach another 9000% improvement in the response time as a median (Creating a cart with 6 items):

|   | Min (ms)  | Median (ms)  | Max (ms)  | Median Improvement (%)
|---|:-:|---|---|---|
| Before optimisation  | 1200  | 9999 | 12698  |  N/A
| After optimisation | 63  | 252  | 500  | 39x
| After re optimisation | 56 | 82  | 399  | 121x
| After including addressed feedback | 65 | 202  | 495  | 49x

FIXES CORE-722
This commit is contained in:
Adrien de Peretti
2022-12-07 14:39:12 +00:00
committed by GitHub
parent 3b2c929408
commit 42d9c7222b
71 changed files with 1204 additions and 439 deletions
@@ -1,6 +1,6 @@
const path = require("path")
const fs = require("fs/promises")
import { sep, resolve } from "path"
import { resolve, sep } from "path"
const setupServer = require("../../../../helpers/setup-server")
const { useApi } = require("../../../../helpers/use-api")
@@ -31,7 +31,6 @@ describe("Batchjob with type order-export", () => {
cwd,
redisUrl: "redis://127.0.0.1:6379",
uploadDir: __dirname,
verbose: false,
})
})
@@ -66,7 +66,6 @@ describe("Price list import batch job", () => {
cwd,
redisUrl: "redis://127.0.0.1:6379",
uploadDir: __dirname,
verbose: false,
})
})
@@ -16,7 +16,7 @@ const adminReqConfig = {
},
}
jest.setTimeout(100000000)
jest.setTimeout(180000)
describe("Batch job of product-export type", () => {
let medusaProcess
@@ -31,7 +31,6 @@ describe("Batch job of product-export type", () => {
cwd,
redisUrl: "redis://127.0.0.1:6379",
uploadDir: __dirname,
verbose: false,
})
})
@@ -61,7 +61,6 @@ describe("Product import - Sales Channel", () => {
env: { MEDUSA_FF_SALES_CHANNELS: true },
redisUrl: "redis://127.0.0.1:6379",
uploadDir: __dirname,
verbose: false,
})
dbConnection = connection
medusaProcess = process
@@ -59,7 +59,6 @@ describe("Product import batch job", () => {
cwd,
redisUrl: "redis://127.0.0.1:6379",
uploadDir: __dirname,
verbose: false,
})
})