@medusajs/pricing 3.0.0-snapshot-20250408170244 → 3.0.0-snapshot-20250409083720

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,6 @@
1
+ import { Migration } from '@mikro-orm/migrations';
2
+ export declare class Migration20250408145122 extends Migration {
3
+ up(): Promise<void>;
4
+ down(): Promise<void>;
5
+ }
6
+ //# sourceMappingURL=Migration20250408145122.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Migration20250408145122.d.ts","sourceRoot":"","sources":["../../src/migrations/Migration20250408145122.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAElD,qBAAa,uBAAwB,SAAQ,SAAS;IAErC,EAAE,IAAI,OAAO,CAAC,IAAI,CAAC;IAOnB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAOrC"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Migration20250408145122 = void 0;
4
+ const migrations_1 = require("@mikro-orm/migrations");
5
+ class Migration20250408145122 extends migrations_1.Migration {
6
+ async up() {
7
+ this.addSql(`CREATE INDEX IF NOT EXISTS "IDX_price_list_rule_attribute" ON "price_list_rule" (attribute) WHERE deleted_at IS NULL;`);
8
+ this.addSql(`CREATE INDEX IF NOT EXISTS "IDX_price_rule_attribute_value" ON "price_rule" (attribute, value) WHERE deleted_at IS NULL;`);
9
+ this.addSql(`CREATE INDEX IF NOT EXISTS "IDX_price_rule_operator_value" ON "price_rule" (operator, value) WHERE deleted_at IS NULL;`);
10
+ }
11
+ async down() {
12
+ this.addSql(`drop index if exists "IDX_price_list_rule_attribute";`);
13
+ this.addSql(`drop index if exists "IDX_price_rule_attribute_value";`);
14
+ this.addSql(`drop index if exists "IDX_price_rule_operator_value";`);
15
+ }
16
+ }
17
+ exports.Migration20250408145122 = Migration20250408145122;
18
+ //# sourceMappingURL=Migration20250408145122.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Migration20250408145122.js","sourceRoot":"","sources":["../../src/migrations/Migration20250408145122.ts"],"names":[],"mappings":";;;AAAA,sDAAkD;AAElD,MAAa,uBAAwB,SAAQ,sBAAS;IAE3C,KAAK,CAAC,EAAE;QACf,IAAI,CAAC,MAAM,CAAC,uHAAuH,CAAC,CAAC;QAErI,IAAI,CAAC,MAAM,CAAC,0HAA0H,CAAC,CAAC;QACxI,IAAI,CAAC,MAAM,CAAC,wHAAwH,CAAC,CAAC;IACxI,CAAC;IAEQ,KAAK,CAAC,IAAI;QACjB,IAAI,CAAC,MAAM,CAAC,uDAAuD,CAAC,CAAC;QAErE,IAAI,CAAC,MAAM,CAAC,wDAAwD,CAAC,CAAC;QACtE,IAAI,CAAC,MAAM,CAAC,uDAAuD,CAAC,CAAC;IACvE,CAAC;CAEF;AAhBD,0DAgBC"}
@@ -1 +1 @@
1
- {"version":3,"file":"price-list-rule.d.ts","sourceRoot":"","sources":["../../src/models/price-list-rule.ts"],"names":[],"mappings":"AAGA,QAAA,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oBAcf,CAAA;AAEJ,eAAe,aAAa,CAAA"}
1
+ {"version":3,"file":"price-list-rule.d.ts","sourceRoot":"","sources":["../../src/models/price-list-rule.ts"],"names":[],"mappings":"AAGA,QAAA,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oBAkBf,CAAA;AAEJ,eAAe,aAAa,CAAA"}
@@ -19,6 +19,10 @@ const PriceListRule = utils_1.model
19
19
  on: ["price_list_id"],
20
20
  where: "deleted_at IS NULL",
21
21
  },
22
+ {
23
+ on: ["attribute"],
24
+ where: "deleted_at IS NULL",
25
+ },
22
26
  ]);
23
27
  exports.default = PriceListRule;
24
28
  //# sourceMappingURL=price-list-rule.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"price-list-rule.js","sourceRoot":"","sources":["../../src/models/price-list-rule.ts"],"names":[],"mappings":";;;;;AAAA,qDAAiD;AACjD,8DAAoC;AAEpC,MAAM,aAAa,GAAG,aAAK;KACxB,MAAM,CAAC,eAAe,EAAE;IACvB,EAAE,EAAE,aAAK,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC,UAAU,EAAE;IAC9C,SAAS,EAAE,aAAK,CAAC,IAAI,EAAE;IACvB,KAAK,EAAE,aAAK,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE;IAC9B,UAAU,EAAE,aAAK,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,oBAAS,EAAE;QAC3C,QAAQ,EAAE,kBAAkB;KAC7B,CAAC;CACH,CAAC;KACD,OAAO,CAAC;IACP;QACE,EAAE,EAAE,CAAC,eAAe,CAAC;QACrB,KAAK,EAAE,oBAAoB;KAC5B;CACF,CAAC,CAAA;AAEJ,kBAAe,aAAa,CAAA"}
1
+ {"version":3,"file":"price-list-rule.js","sourceRoot":"","sources":["../../src/models/price-list-rule.ts"],"names":[],"mappings":";;;;;AAAA,qDAAiD;AACjD,8DAAoC;AAEpC,MAAM,aAAa,GAAG,aAAK;KACxB,MAAM,CAAC,eAAe,EAAE;IACvB,EAAE,EAAE,aAAK,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC,UAAU,EAAE;IAC9C,SAAS,EAAE,aAAK,CAAC,IAAI,EAAE;IACvB,KAAK,EAAE,aAAK,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE;IAC9B,UAAU,EAAE,aAAK,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,oBAAS,EAAE;QAC3C,QAAQ,EAAE,kBAAkB;KAC7B,CAAC;CACH,CAAC;KACD,OAAO,CAAC;IACP;QACE,EAAE,EAAE,CAAC,eAAe,CAAC;QACrB,KAAK,EAAE,oBAAoB;KAC5B;IACD;QACE,EAAE,EAAE,CAAC,WAAW,CAAC;QACjB,KAAK,EAAE,oBAAoB;KAC5B;CACF,CAAC,CAAA;AAEJ,kBAAe,aAAa,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"price-rule.d.ts","sourceRoot":"","sources":["../../src/models/price-rule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,mBAAmB,EAAE,MAAM,2BAA2B,CAAA;AAGtE,QAAA,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gBAiBX,CAAA;AAEJ,eAAe,SAAS,CAAA"}
1
+ {"version":3,"file":"price-rule.d.ts","sourceRoot":"","sources":["../../src/models/price-rule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,mBAAmB,EAAE,MAAM,2BAA2B,CAAA;AAGtE,QAAA,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gBAyBX,CAAA;AAEJ,eAAe,SAAS,CAAA"}
@@ -22,6 +22,14 @@ const PriceRule = utils_1.model
22
22
  where: "deleted_at IS NULL",
23
23
  unique: true,
24
24
  },
25
+ {
26
+ on: ["attribute", "value"],
27
+ where: "deleted_at IS NULL",
28
+ },
29
+ {
30
+ on: ["operator", "value"],
31
+ where: "deleted_at IS NULL",
32
+ },
25
33
  ]);
26
34
  exports.default = PriceRule;
27
35
  //# sourceMappingURL=price-rule.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"price-rule.js","sourceRoot":"","sources":["../../src/models/price-rule.ts"],"names":[],"mappings":";;;;;AAAA,qDAAsE;AACtE,oDAA2B;AAE3B,MAAM,SAAS,GAAG,aAAK;KACpB,MAAM,CAAC,WAAW,EAAE;IACnB,EAAE,EAAE,aAAK,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC,UAAU,EAAE;IAC9C,SAAS,EAAE,aAAK,CAAC,IAAI,EAAE;IACvB,KAAK,EAAE,aAAK,CAAC,IAAI,EAAE;IACnB,Q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AAM,EAAE,IAAI;KACb;IACD;QACE,EAAE,EAAE,CAAC,WAAW,EAAE,OAAO,CAAC;QAC1B,KAAK,EAAE,oBAAoB;KAC5B;IACD;QACE,EAAE,EAAE,CAAC,UAAU,EAAE,OAAO,CAAC;QACzB,KAAK,EAAE,oBAAoB;KAC5B;CACF,CAAC,CAAA;AAEJ,kBAAe,SAAS,CAAA"}
@@ -3,5 +3,6 @@ import { CalculatedPriceSetDTO, Context, PricingContext, PricingFilters, Pricing
3
3
  export declare class PricingRepository extends MikroOrmBase implements PricingRepositoryService {
4
4
  constructor();
5
5
  calculatePrices(pricingFilters: PricingFilters, pricingContext?: PricingContext, sharedContext?: Context): Promise<CalculatedPriceSetDTO[]>;
6
+ private getAttributesFromRuleTables;
6
7
  }
7
8
  //# sourceMappingURL=pricing.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"pricing.d.ts","sourceRoot":"","sources":["../../src/repositories/pricing.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,YAAY,EAGb,MAAM,2BAA2B,CAAA;AAElC,OAAO,EACL,qBAAqB,EACrB,OAAO,EACP,cAAc,EACd,cAAc,EACd,wBAAwB,EACzB,MAAM,2BAA2B,CAAA;AAGlC,qBAAa,iBACX,SAAQ,YACR,YAAW,wBAAwB;;IAQ7B,eAAe,CACnB,cAAc,EAAE,cAAc,EAC9B,cAAc,GAAE,cAAgC,EAChD,aAAa,GAAE,OAAY,GAC1B,OAAO,CAAC,qBAAqB,EAAE,CAAC;CAmQpC"}
1
+ {"version":3,"file":"pricing.d.ts","sourceRoot":"","sources":["../../src/repositories/pricing.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,YAAY,EAGb,MAAM,2BAA2B,CAAA;AAElC,OAAO,EACL,qBAAqB,EACrB,OAAO,EACP,cAAc,EACd,cAAc,EACd,wBAAwB,EACzB,MAAM,2BAA2B,CAAA;AAKlC,qBAAa,iBACX,SAAQ,YACR,YAAW,wBAAwB;;IAQ7B,eAAe,CACnB,cAAc,EAAE,cAAc,EAC9B,cAAc,GAAE,cAAgC,EAChD,aAAa,GAAE,OAAY,GAC1B,OAAO,CAAC,qBAAqB,EAAE,CAAC;YA6NrB,2BAA2B;CAe1C"}
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PricingRepository = void 0;
4
4
  const utils_1 = require("@medusajs/framework/utils");
5
+ // Simple cache implementation
5
6
  class PricingRepository extends utils_1.MikroOrmBase {
6
7
  constructor() {
7
8
  // @ts-ignore
@@ -12,36 +13,17 @@ class PricingRepository extends utils_1.MikroOrmBase {
12
13
  const manager = this.getActiveManager(sharedContext);
13
14
  const knex = manager.getKnex();
14
15
  const context = pricingContext.context || {};
15
- // Quantity is used to scope money amounts based on min_quantity and max_quantity.
16
- // We should potentially think of reserved words in pricingContext that can't be used in rules
17
- // or have a separate pricing options that accept things like quantity, price_list_id and other
18
- // pricing module features
16
+ // Extract quantity and currency from context
19
17
  const quantity = context.quantity;
20
18
  delete context.quantity;
21
- // Currency code here is a required param.
19
+ // Currency code is required
22
20
  const currencyCode = context.currency_code;
23
21
  delete context.currency_code;
24
22
  if (!currencyCode) {
25
23
  throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Method calculatePrices requires currency_code in the pricing context`);
26
24
  }
27
- const isContextPresent = Object.entries(context).length || !!currencyCode;
28
- // Only if the context is present do we need to query the database.
29
- // We don't get anything from the db otherwise.
30
- if (!isContextPresent) {
31
- return [];
32
- }
33
- // We query the rule tables to get all whitelisted rule attributes
34
- // This will help cleanup the query and do a db query on only necessary rule attributes.
35
- const priceRuleAttributesQuery = knex("price_rule")
36
- .distinct("attribute")
37
- .pluck("attribute");
38
- const priceListRuleAttributesQuery = knex("price_list_rule")
39
- .distinct("attribute")
40
- .pluck("attribute");
41
- const [ruleAttributes, priceListRuleAttributes] = await (0, utils_1.promiseAll)([
42
- priceRuleAttributesQuery,
43
- priceListRuleAttributesQuery,
44
- ]);
25
+ // Generate flatten key-value pairs for rule matching
26
+ const [ruleAttributes, priceListRuleAttributes] = await this.getAttributesFromRuleTables(knex);
45
27
  const allowedRuleAttributes = [
46
28
  ...ruleAttributes,
47
29
  ...priceListRuleAttributes,
@@ -53,156 +35,177 @@ class PricingRepository extends utils_1.MikroOrmBase {
53
35
  return (allowedRuleAttributes.includes(key) &&
54
36
  (isValuePresent || isArrayPresent));
55
37
  });
56
- // Gets all the prices where rules match for each of the contexts
57
- // that the price set is configured for
58
- const priceSubQueryKnex = knex({
59
- price: "price",
60
- })
38
+ const hasComplexContext = flattenedContext.length > 0;
39
+ // Base query with efficient index lookups
40
+ const query = knex
61
41
  .select({
62
42
  id: "price.id",
43
+ price_set_id: "price.price_set_id",
63
44
  amount: "price.amount",
64
45
  raw_amount: "price.raw_amount",
65
46
  min_quantity: "price.min_quantity",
66
47
  max_quantity: "price.max_quantity",
67
48
  currency_code: "price.currency_code",
68
- deleted_at: "price.deleted_at",
69
- price_set_id: "price.price_set_id",
70
- rules_count: "price.rules_count",
71
49
  price_list_id: "price.price_list_id",
72
- pl_rules_count: "pl.rules_count",
73
- pl_type: "pl.type",
74
- has_price_list: knex.raw("case when price.price_list_id IS NULL then False else True end"),
75
- })
76
- .leftJoin("price_rule as pr", "pr.price_id", "price.id")
77
- .leftJoin("price_list as pl", function () {
78
- this.on("pl.id", "price.price_list_id").andOn("pl.status", knex.raw("?", [utils_1.PriceListStatus.ACTIVE]));
50
+ price_list_type: "pl.type",
51
+ rules_count: "price.rules_count",
52
+ price_list_rules_count: "pl.rules_count",
79
53
  })
80
- .leftJoin("price_list_rule as plr", "plr.price_list_id", "pl.id")
81
- .groupBy("price.id", "pl.id")
82
- .having(knex.raw("count(pr.attribute) = price.rules_count AND price.price_list_id IS NULL"))
83
- .orHaving(knex.raw("count(DISTINCT plr.attribute) = pl.rules_count AND price.price_list_id IS NOT NULL"));
84
- const buildOperatorQueries = (operatorGroupBuilder, value) => {
85
- operatorGroupBuilder
86
- .where((operatorBuilder) => {
87
- operatorBuilder
88
- .where("pr.operator", "gte")
89
- .whereRaw("? >= pr.value::numeric", [value]);
90
- })
91
- .orWhere((operatorBuilder) => {
92
- operatorBuilder
93
- .where("pr.operator", "gt")
94
- .whereRaw("? > pr.value::numeric", [value]);
95
- })
96
- .orWhere((operatorBuilder) => {
97
- operatorBuilder
98
- .where("pr.operator", "lt")
99
- .whereRaw("? < pr.value::numeric", [value]);
54
+ .from("price")
55
+ .whereIn("price.price_set_id", pricingFilters.id)
56
+ .andWhere("price.currency_code", currencyCode)
57
+ .whereNull("price.deleted_at");
58
+ // Apply quantity filter
59
+ if (quantity !== undefined) {
60
+ query.andWhere(function () {
61
+ this.where(function () {
62
+ this.where("price.min_quantity", "<=", quantity).andWhere("price.max_quantity", ">=", quantity);
63
+ }).orWhere(function () {
64
+ this.whereNull("price.min_quantity").whereNull("price.max_quantity");
65
+ });
66
+ });
67
+ }
68
+ else {
69
+ query.andWhere(function () {
70
+ this.where("price.min_quantity", "<=", 1).orWhereNull("price.min_quantity");
71
+ });
72
+ }
73
+ // Efficient price list join with index usage
74
+ query.leftJoin("price_list as pl", function () {
75
+ this.on("pl.id", "=", "price.price_list_id")
76
+ .andOn("pl.status", "=", knex.raw("?", [utils_1.PriceListStatus.ACTIVE]))
77
+ .andOn(function () {
78
+ this.onNull("pl.deleted_at");
100
79
  })
101
- .orWhere((operatorBuilder) => {
102
- operatorBuilder
103
- .where("pr.operator", "lte")
104
- .whereRaw("? <= pr.value::numeric", [value]);
80
+ .andOn(function () {
81
+ this.onNull("pl.starts_at").orOn("pl.starts_at", "<=", knex.fn.now());
105
82
  })
106
- .orWhere((operatorBuilder) => {
107
- operatorBuilder
108
- .where("pr.operator", "eq")
109
- .whereRaw("? = pr.value::numeric", [value]);
110
- });
111
- };
112
- priceSubQueryKnex.orWhere((priceBuilder) => {
113
- priceBuilder
114
- .whereNull("price.price_list_id")
115
- .andWhere((withoutPriceListBuilder) => {
116
- for (const [key, value] of flattenedContext) {
117
- withoutPriceListBuilder.orWhere((orBuilder) => {
118
- orBuilder.where("pr.attribute", key);
119
- if (typeof value === "number") {
120
- buildOperatorQueries(orBuilder, value);
121
- }
122
- else {
123
- const normalizeValue = Array.isArray(value) ? value : [value];
124
- orBuilder.whereIn("pr.value", normalizeValue);
125
- }
126
- });
127
- }
128
- withoutPriceListBuilder.orWhere("price.rules_count", "=", 0);
83
+ .andOn(function () {
84
+ this.onNull("pl.ends_at").orOn("pl.ends_at", ">=", knex.fn.now());
129
85
  });
130
86
  });
131
- priceSubQueryKnex.orWhere((q) => {
132
- q.whereNotNull("price.price_list_id")
133
- .whereNull("pl.deleted_at")
134
- .andWhere(function () {
135
- this.whereNull("pl.starts_at").orWhere("pl.starts_at", "<=", knex.fn.now());
87
+ // OPTIMIZATION: Only add complex rule filtering when necessary
88
+ if (hasComplexContext) {
89
+ // For price rules - direct check that ALL rules match
90
+ const priceRuleConditions = knex.raw(`
91
+ (
92
+ price.rules_count = 0 OR
93
+ (
94
+ /* Count all matching rules and compare to total rule count */
95
+ SELECT COUNT(*)
96
+ FROM price_rule pr
97
+ WHERE pr.price_id = price.id
98
+ AND pr.deleted_at IS NULL
99
+ AND (
100
+ ${flattenedContext
101
+ .map(([key, value]) => {
102
+ if (typeof value === "number") {
103
+ return `
104
+ (pr.attribute = ? AND (
105
+ (pr.operator = 'eq' AND pr.value = ?) OR
106
+ (pr.operator = 'gt' AND ? > pr.value::numeric) OR
107
+ (pr.operator = 'gte' AND ? >= pr.value::numeric) OR
108
+ (pr.operator = 'lt' AND ? < pr.value::numeric) OR
109
+ (pr.operator = 'lte' AND ? <= pr.value::numeric)
110
+ ))
111
+ `;
112
+ }
113
+ else {
114
+ const normalizeValue = Array.isArray(value)
115
+ ? value
116
+ : [value];
117
+ const placeholders = normalizeValue.map(() => "?").join(",");
118
+ return `(pr.attribute = ? AND pr.value IN (${placeholders}))`;
119
+ }
136
120
  })
137
- .andWhere(function () {
138
- this.whereNull("pl.ends_at").orWhere("pl.ends_at", ">=", knex.fn.now());
121
+ .join(" OR ")}
122
+ )
123
+ ) = (
124
+ /* Get total rule count */
125
+ SELECT COUNT(*)
126
+ FROM price_rule pr
127
+ WHERE pr.price_id = price.id
128
+ AND pr.deleted_at IS NULL
129
+ )
130
+ )
131
+ `, flattenedContext.flatMap(([key, value]) => {
132
+ if (typeof value === "number") {
133
+ return [key, value.toString(), value, value, value, value];
134
+ }
135
+ else {
136
+ const normalizeValue = Array.isArray(value) ? value : [value];
137
+ return [key, ...normalizeValue];
138
+ }
139
+ }));
140
+ // For price list rules - direct check that ALL rules match
141
+ const priceListRuleConditions = knex.raw(`
142
+ (
143
+ pl.rules_count = 0 OR
144
+ (
145
+ /* Count all matching rules and compare to total rule count */
146
+ SELECT COUNT(*)
147
+ FROM price_list_rule plr
148
+ WHERE plr.price_list_id = pl.id
149
+ AND plr.deleted_at IS NULL
150
+ AND (
151
+ ${flattenedContext
152
+ .map(([key, value]) => {
153
+ return `(plr.attribute = ? AND plr.value @> ?)`;
139
154
  })
140
- .andWhere(function () {
141
- this.andWhere(function () {
142
- for (const [key, value] of flattenedContext) {
143
- this.orWhere({ "plr.attribute": key });
144
- this.where("plr.value", "@>", JSON.stringify(Array.isArray(value) ? value : [value]));
145
- }
146
- this.orWhere("pl.rules_count", "=", 0);
147
- });
148
- this.andWhere(function () {
149
- this.andWhere((contextBuilder) => {
150
- for (const [key, value] of flattenedContext) {
151
- contextBuilder.orWhere((orBuilder) => {
152
- orBuilder.where("pr.attribute", key);
153
- if (typeof value === "number") {
154
- buildOperatorQueries(orBuilder, value);
155
- }
156
- else {
157
- const normalizeValue = Array.isArray(value)
158
- ? value
159
- : [value];
160
- orBuilder.whereIn("pr.value", normalizeValue);
161
- }
162
- });
163
- }
164
- contextBuilder.andWhere("price.rules_count", ">", 0);
165
- });
166
- this.orWhere("price.rules_count", "=", 0);
155
+ .join(" OR ")}
156
+ )
157
+ ) = (
158
+ /* Get total rule count */
159
+ SELECT COUNT(*)
160
+ FROM price_list_rule plr
161
+ WHERE plr.price_list_id = pl.id
162
+ AND plr.deleted_at IS NULL
163
+ )
164
+ )
165
+ `, flattenedContext.flatMap(([key, value]) => {
166
+ return [key, JSON.stringify(Array.isArray(value) ? value : [value])];
167
+ }));
168
+ query.where((qb) => {
169
+ qb.whereNull("price.price_list_id")
170
+ .andWhereRaw(priceRuleConditions)
171
+ .orWhere((qb2) => {
172
+ qb2
173
+ .whereNotNull("price.price_list_id")
174
+ .whereRaw(priceListRuleConditions)
175
+ .andWhereRaw(priceRuleConditions);
167
176
  });
168
177
  });
169
- });
170
- const priceSetQueryKnex = knex({
171
- ps: "price_set",
172
- })
173
- .select({
174
- id: "price.id",
175
- price_set_id: "ps.id",
176
- amount: "price.amount",
177
- raw_amount: "price.raw_amount",
178
- min_quantity: "price.min_quantity",
179
- max_quantity: "price.max_quantity",
180
- currency_code: "price.currency_code",
181
- rules_count: "price.rules_count",
182
- pl_rules_count: "price.pl_rules_count",
183
- price_list_type: "price.pl_type",
184
- price_list_id: "price.price_list_id",
185
- all_rules_count: knex.raw("COALESCE(price.rules_count, 0) + COALESCE(price.pl_rules_count, 0)"),
186
- })
187
- .join(priceSubQueryKnex.as("price"), "price.price_set_id", "ps.id")
188
- .whereIn("ps.id", pricingFilters.id)
189
- .andWhere("price.currency_code", "=", currencyCode)
190
- .whereNull("price.deleted_at")
191
- .orderBy([
192
- { column: "price.has_price_list", order: "asc" },
193
- { column: "all_rules_count", order: "desc" },
194
- { column: "amount", order: "asc" },
195
- ]);
196
- if (quantity) {
197
- priceSetQueryKnex.where("price.min_quantity", "<=", quantity);
198
- priceSetQueryKnex.andWhere("price.max_quantity", ">=", quantity);
199
178
  }
200
179
  else {
201
- priceSetQueryKnex.andWhere(function () {
202
- this.andWhere("price.min_quantity", "<=", "1").orWhereNull("price.min_quantity");
180
+ // Simple case - just get prices with no rules or price lists with no rules
181
+ query.where(function () {
182
+ this.where("price.rules_count", 0).orWhere(function () {
183
+ this.whereNotNull("price.price_list_id").where("pl.rules_count", 0);
184
+ });
203
185
  });
204
186
  }
205
- return await priceSetQueryKnex;
187
+ // Optimized ordering to help query planner and preserve price list precedence
188
+ query
189
+ .orderByRaw("price.price_list_id IS NOT NULL DESC")
190
+ .orderByRaw("price.rules_count + COALESCE(pl.rules_count, 0) DESC") // More specific rules first
191
+ .orderBy("pl.id", "asc") // Order by price list ID to ensure first created price list takes precedence
192
+ .orderBy("price.amount", "asc"); // For non-price list prices, cheaper ones first
193
+ // Execute the optimized query
194
+ return await query;
195
+ }
196
+ // Helper method to get attributes from rule tables
197
+ async getAttributesFromRuleTables(knex) {
198
+ // Using distinct queries for better performance
199
+ const priceRuleAttributesQuery = knex("price_rule")
200
+ .distinct("attribute")
201
+ .pluck("attribute");
202
+ const priceListRuleAttributesQuery = knex("price_list_rule")
203
+ .distinct("attribute")
204
+ .pluck("attribute");
205
+ return await (0, utils_1.promiseAll)([
206
+ priceRuleAttributesQuery,
207
+ priceListRuleAttributesQuery,
208
+ ]);
206
209
  }
207
210
  }
208
211
  exports.PricingRepository = PricingRepository;
@@ -1 +1 @@
1
- {"version":3,"file":"pricing.js","sourceRoot":"","sources":["../../src/repositories/pricing.ts"],"names":[],"mappings":";;;AAAA,qDAOkC;AAWlC,MAAa,iBACX,SAAQ,oBAAY;IAGpB;QACE,aAAa;QACb,8CAA8C;QAC9C,KAAK,CAAC,GAAG,SAAS,CAAC,CAAA;IACrB,CAAC;IAED,KAAK,CAAC,eAAe,CACnB,cAA8B,EAC9B,iBAAiC,EAAE,OAAO,EAAE,EAAE,EAAE,EAChD,gBAAyB,EAAE;QAE3B,MAAM,OAAO,GAAG,IAAI,CAAC,gBAAgB,CAAmB,aAAa,CAAC,CAAA;QACtE,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,EAAE,CAAA;QAC9B,MAAM,OAAO,GAAG,cAAc,CAAC,OAAO,IAAI,EAAE,CAAA;QAE5C,kFAAkF;QAClF,8FAA8F;QAC9F,+FAA+F;QAC/F,0BAA0B;QAC1B,M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9E,KAAK;aACF,UAAU,CAAC,sCAAsC,CAAC;aAClD,UAAU,CAAC,sDAAsD,CAAC,CAAC,4BAA4B;aAC/F,OAAO,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,6EAA6E;aACrG,OAAO,CAAC,cAAc,EAAE,KAAK,CAAC,CAAA,CAAC,gDAAgD;QAElF,8BAA8B;QAC9B,OAAO,MAAM,KAAK,CAAA;IACpB,CAAC;IAED,mDAAmD;IAC3C,KAAK,CAAC,2BAA2B,CAAC,IAAU;QAClD,gDAAgD;QAChD,MAAM,wBAAwB,GAAG,IAAI,CAAC,YAAY,CAAC;aAChD,QAAQ,CAAC,WAAW,CAAC;aACrB,KAAK,CAAC,WAAW,CAAC,CAAA;QAErB,MAAM,4BAA4B,GAAG,IAAI,CAAC,iBAAiB,CAAC;aACzD,QAAQ,CAAC,WAAW,CAAC;aACrB,KAAK,CAAC,WAAW,CAAC,CAAA;QAErB,OAAO,MAAM,IAAA,kBAAU,EAAC;YACtB,wBAAwB;YACxB,4BAA4B;SAC7B,CAAC,CAAA;IACJ,CAAC;CACF;AA1PD,8CA0PC"}
@@ -1 +1 @@
1
- {"root":["../src/index.ts","../src/joiner-config.ts","../src/migrations/Migration20230929122253.ts","../src/migrations/Migration20240322094407.ts","../src/migrations/Migration20240322113359.ts","../src/migrations/Migration20240322120125.ts","../src/migrations/Migration20240626133555.ts","../src/migrations/Migration20240704094505.ts","../src/migrations/Migration20241127114534.ts","../src/migrations/Migration20241127223829.ts","../src/migrations/Migration20241128055359.ts","../src/migrations/Migration20241212190401.ts","../src/models/index.ts","../src/models/price-list-rule.ts","../src/models/price-list.ts","../src/models/price-preference.ts","../src/models/price-rule.ts","../src/models/price-set.ts","../src/models/price.ts","../src/repositories/index.ts","../src/repositories/pricing.ts","../src/schema/index.ts","../src/services/index.ts","../src/services/pricing-module.ts","../src/services/__tests__/index.spec.ts","../src/types/index.ts","../src/types/services/index.ts","../src/utils/events.ts","../src/utils/index.ts","../src/utils/validate-price-list-dates.ts"],"version":"5.6.2"}
1
+ {"root":["../src/index.ts","../src/joiner-config.ts","../src/migrations/Migration20230929122253.ts","../src/migrations/Migration20240322094407.ts","../src/migrations/Migration20240322113359.ts","../src/migrations/Migration20240322120125.ts","../src/migrations/Migration20240626133555.ts","../src/migrations/Migration20240704094505.ts","../src/migrations/Migration20241127114534.ts","../src/migrations/Migration20241127223829.ts","../src/migrations/Migration20241128055359.ts","../src/migrations/Migration20241212190401.ts","../src/migrations/Migration20250408145122.ts","../src/models/index.ts","../src/models/price-list-rule.ts","../src/models/price-list.ts","../src/models/price-preference.ts","../src/models/price-rule.ts","../src/models/price-set.ts","../src/models/price.ts","../src/repositories/index.ts","../src/repositories/pricing.ts","../src/schema/index.ts","../src/services/index.ts","../src/services/pricing-module.ts","../src/services/__tests__/index.spec.ts","../src/types/index.ts","../src/types/services/index.ts","../src/utils/events.ts","../src/utils/index.ts","../src/utils/validate-price-list-dates.ts"],"version":"5.6.2"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@medusajs/pricing",
3
- "version": "3.0.0-snapshot-20250408170244",
3
+ "version": "3.0.0-snapshot-20250409083720",
4
4
  "description": "Medusa Pricing module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -36,8 +36,8 @@
36
36
  "orm:cache:clear": " MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts medusa-mikro-orm cache:clear"
37
37
  },
38
38
  "devDependencies": {
39
- "@medusajs/framework": "3.0.0-snapshot-20250408170244",
40
- "@medusajs/test-utils": "3.0.0-snapshot-20250408170244",
39
+ "@medusajs/framework": "3.0.0-snapshot-20250409083720",
40
+ "@medusajs/test-utils": "3.0.0-snapshot-20250409083720",
41
41
  "@mikro-orm/cli": "6.4.3",
42
42
  "@mikro-orm/core": "6.4.3",
43
43
  "@mikro-orm/migrations": "6.4.3",
@@ -50,7 +50,7 @@
50
50
  "typescript": "^5.6.2"
51
51
  },
52
52
  "peerDependencies": {
53
- "@medusajs/framework": "3.0.0-snapshot-20250408170244",
53
+ "@medusajs/framework": "3.0.0-snapshot-20250409083720",
54
54
  "@mikro-orm/core": "6.4.3",
55
55
  "@mikro-orm/migrations": "6.4.3",
56
56
  "@mikro-orm/postgresql": "6.4.3",