**What** I have removed the check for the context key where it was fetching all attributes available and then stripping out the one that does not exists.. On big dataset these would remove multiple hundreds of ms of query execution
36 lines
858 B
TypeScript
36 lines
858 B
TypeScript
import { model, PricingRuleOperator } from "@medusajs/framework/utils"
|
|
import Price from "./price"
|
|
|
|
const PriceRule = model
|
|
.define("PriceRule", {
|
|
id: model.id({ prefix: "prule" }).primaryKey(),
|
|
attribute: model.text(),
|
|
value: model.text(),
|
|
operator: model.enum(PricingRuleOperator).default(PricingRuleOperator.EQ),
|
|
priority: model.number().default(0),
|
|
price: model.belongsTo(() => Price, {
|
|
mappedBy: "price_rules",
|
|
}),
|
|
})
|
|
.indexes([
|
|
{
|
|
on: ["price_id", "attribute", "operator"],
|
|
where: "deleted_at IS NULL",
|
|
unique: true,
|
|
},
|
|
{
|
|
on: ["attribute"],
|
|
where: "deleted_at IS NULL",
|
|
},
|
|
{
|
|
on: ["attribute", "value"],
|
|
where: "deleted_at IS NULL",
|
|
},
|
|
{
|
|
on: ["operator", "value"],
|
|
where: "deleted_at IS NULL",
|
|
},
|
|
])
|
|
|
|
export default PriceRule
|