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

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"}
@@ -0,0 +1,6 @@
1
+ import { Migration } from '@mikro-orm/migrations';
2
+ export declare class Migration20250409122219 extends Migration {
3
+ up(): Promise<void>;
4
+ down(): Promise<void>;
5
+ }
6
+ //# sourceMappingURL=Migration20250409122219.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Migration20250409122219.d.ts","sourceRoot":"","sources":["../../src/migrations/Migration20250409122219.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAElD,qBAAa,uBAAwB,SAAQ,SAAS;IAErC,EAAE,IAAI,OAAO,CAAC,IAAI,CAAC;IAInB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAIrC"}
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Migration20250409122219 = void 0;
4
+ const migrations_1 = require("@mikro-orm/migrations");
5
+ class Migration20250409122219 extends migrations_1.Migration {
6
+ async up() {
7
+ this.addSql(`CREATE INDEX IF NOT EXISTS "IDX_price_rule_attribute" ON "price_rule" (attribute) WHERE deleted_at IS NULL;`);
8
+ }
9
+ async down() {
10
+ this.addSql(`drop index if exists "IDX_price_rule_attribute";`);
11
+ }
12
+ }
13
+ exports.Migration20250409122219 = Migration20250409122219;
14
+ //# sourceMappingURL=Migration20250409122219.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Migration20250409122219.js","sourceRoot":"","sources":["../../src/migrations/Migration20250409122219.ts"],"names":[],"mappings":";;;AAAA,sDAAkD;AAElD,MAAa,uBAAwB,SAAQ,sBAAS;IAE3C,KAAK,CAAC,EAAE;QACf,IAAI,CAAC,MAAM,CAAC,6GAA6G,CAAC,CAAC;IAC7H,CAAC;IAEQ,KAAK,CAAC,IAAI;QACjB,IAAI,CAAC,MAAM,CAAC,kDAAkD,CAAC,CAAC;IAClE,CAAC;CAEF;AAVD,0DAUC"}
@@ -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":";;;;;A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A;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gBA6BX,CAAA;AAEJ,eAAe,SAAS,CAAA"}
@@ -22,6 +22,18 @@ const PriceRule = utils_1.model
22
22
  where: "deleted_at IS NULL",
23
23
  unique: true,
24
24
  },
25
+ {
26
+ on: ["attribute"],
27
+ where: "deleted_at IS NULL",
28
+ },
29
+ {
30
+ on: ["attribute", "value"],
31
+ where: "deleted_at IS NULL",
32
+ },
33
+ {
34
+ on: ["operator", "value"],
35
+ where: "deleted_at IS NULL",
36
+ },
25
37
  ]);
26
38
  exports.default = PriceRule;
27
39
  //# 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,EA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B;QAC3B,MAAM,EAAE,IAAI;KACb;IACD;QACE,EAAE,EAAE,CAAC,WAAW,CAAC;QACjB,KAAK,EAAE,oBAAoB;KAC5B;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"}
@@ -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,EAEb,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;CAgPpC"}
@@ -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,197 +13,208 @@ 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
- ]);
45
- const allowedRuleAttributes = [
46
- ...ruleAttributes,
47
- ...priceListRuleAttributes,
48
- ];
25
+ // Generate flatten key-value pairs for rule matching
49
26
  const flattenedKeyValuePairs = (0, utils_1.flattenObjectToKeyValuePairs)(context);
50
- const flattenedContext = Object.entries(flattenedKeyValuePairs).filter(([key, value]) => {
27
+ // First filter by value presence
28
+ const candidateContext = Object.entries(flattenedKeyValuePairs).filter(([, value]) => {
51
29
  const isValuePresent = !Array.isArray(value) && (0, utils_1.isPresent)(value);
52
30
  const isArrayPresent = Array.isArray(value) && value.flat(1).length;
53
- return (allowedRuleAttributes.includes(key) &&
54
- (isValuePresent || isArrayPresent));
31
+ return isValuePresent || isArrayPresent;
55
32
  });
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
- })
33
+ // If we have potential context keys, efficiently check which ones exist in rules
34
+ const flattenedContext = candidateContext;
35
+ // if (candidateContext.length > 0) {
36
+ // const contextKeys = candidateContext.map(([key]) => key)
37
+ // // Efficient query to check if keys exist in either rule table
38
+ // // This avoids fetching ALL rule attributes - only checks our specific keys
39
+ // const existingKeys = await knex
40
+ // .raw(
41
+ // `
42
+ // SELECT DISTINCT attribute
43
+ // FROM (
44
+ // SELECT attribute FROM price_rule WHERE attribute IN (${contextKeys
45
+ // .map(() => "?")
46
+ // .join(",")})
47
+ // UNION
48
+ // SELECT attribute FROM price_list_rule WHERE attribute IN (${contextKeys
49
+ // .map(() => "?")
50
+ // .join(",")})
51
+ // ) AS combined_attributes
52
+ // `,
53
+ // [...contextKeys, ...contextKeys]
54
+ // )
55
+ // .then((result) => result.rows.map((row) => row.attribute))
56
+ // // Filter context to only include keys that exist in rules
57
+ // flattenedContext = candidateContext.filter(([key]) =>
58
+ // existingKeys.includes(key)
59
+ // )
60
+ // }
61
+ const hasComplexContext = flattenedContext.length > 0;
62
+ // Base query with efficient index lookups
63
+ const query = knex
61
64
  .select({
62
65
  id: "price.id",
66
+ price_set_id: "price.price_set_id",
63
67
  amount: "price.amount",
64
68
  raw_amount: "price.raw_amount",
65
69
  min_quantity: "price.min_quantity",
66
70
  max_quantity: "price.max_quantity",
67
71
  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
72
  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]));
73
+ price_list_type: "pl.type",
74
+ rules_count: "price.rules_count",
75
+ price_list_rules_count: "pl.rules_count",
79
76
  })
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]);
77
+ .from("price")
78
+ .whereIn("price.price_set_id", pricingFilters.id)
79
+ .andWhere("price.currency_code", currencyCode)
80
+ .whereNull("price.deleted_at");
81
+ // Apply quantity filter
82
+ if (quantity !== undefined) {
83
+ query.andWhere(function () {
84
+ this.where(function () {
85
+ this.where("price.min_quantity", "<=", quantity).andWhere("price.max_quantity", ">=", quantity);
86
+ }).orWhere(function () {
87
+ this.whereNull("price.min_quantity").whereNull("price.max_quantity");
88
+ });
89
+ });
90
+ }
91
+ else {
92
+ query.andWhere(function () {
93
+ this.where("price.min_quantity", "<=", 1).orWhereNull("price.min_quantity");
94
+ });
95
+ }
96
+ // Efficient price list join with index usage
97
+ query.leftJoin("price_list as pl", function () {
98
+ this.on("pl.id", "=", "price.price_list_id")
99
+ .andOn("pl.status", "=", knex.raw("?", [utils_1.PriceListStatus.ACTIVE]))
100
+ .andOn(function () {
101
+ this.onNull("pl.deleted_at");
100
102
  })
101
- .orWhere((operatorBuilder) => {
102
- operatorBuilder
103
- .where("pr.operator", "lte")
104
- .whereRaw("? <= pr.value::numeric", [value]);
103
+ .andOn(function () {
104
+ this.onNull("pl.starts_at").orOn("pl.starts_at", "<=", knex.fn.now());
105
105
  })
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);
106
+ .andOn(function () {
107
+ this.onNull("pl.ends_at").orOn("pl.ends_at", ">=", knex.fn.now());
129
108
  });
130
109
  });
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());
110
+ // OPTIMIZATION: Only add complex rule filtering when necessary
111
+ if (hasComplexContext) {
112
+ // For price rules - direct check that ALL rules match
113
+ const priceRuleConditions = knex.raw(`
114
+ (
115
+ price.rules_count = 0 OR
116
+ (
117
+ /* Count all matching rules and compare to total rule count */
118
+ SELECT COUNT(*)
119
+ FROM price_rule pr
120
+ WHERE pr.price_id = price.id
121
+ AND pr.deleted_at IS NULL
122
+ AND (
123
+ ${flattenedContext
124
+ .map(([key, value]) => {
125
+ if (typeof value === "number") {
126
+ return `
127
+ (pr.attribute = ? AND (
128
+ (pr.operator = 'eq' AND pr.value = ?) OR
129
+ (pr.operator = 'gt' AND ? > pr.value::numeric) OR
130
+ (pr.operator = 'gte' AND ? >= pr.value::numeric) OR
131
+ (pr.operator = 'lt' AND ? < pr.value::numeric) OR
132
+ (pr.operator = 'lte' AND ? <= pr.value::numeric)
133
+ ))
134
+ `;
135
+ }
136
+ else {
137
+ const normalizeValue = Array.isArray(value)
138
+ ? value
139
+ : [value];
140
+ const placeholders = normalizeValue.map(() => "?").join(",");
141
+ return `(pr.attribute = ? AND pr.value IN (${placeholders}))`;
142
+ }
136
143
  })
137
- .andWhere(function () {
138
- this.whereNull("pl.ends_at").orWhere("pl.ends_at", ">=", knex.fn.now());
144
+ .join(" OR ")}
145
+ )
146
+ ) = (
147
+ /* Get total rule count */
148
+ SELECT COUNT(*)
149
+ FROM price_rule pr
150
+ WHERE pr.price_id = price.id
151
+ AND pr.deleted_at IS NULL
152
+ )
153
+ )
154
+ `, flattenedContext.flatMap(([key, value]) => {
155
+ if (typeof value === "number") {
156
+ return [key, value.toString(), value, value, value, value];
157
+ }
158
+ else {
159
+ const normalizeValue = Array.isArray(value) ? value : [value];
160
+ return [key, ...normalizeValue];
161
+ }
162
+ }));
163
+ // For price list rules - direct check that ALL rules match
164
+ const priceListRuleConditions = knex.raw(`
165
+ (
166
+ pl.rules_count = 0 OR
167
+ (
168
+ /* Count all matching rules and compare to total rule count */
169
+ SELECT COUNT(*)
170
+ FROM price_list_rule plr
171
+ WHERE plr.price_list_id = pl.id
172
+ AND plr.deleted_at IS NULL
173
+ AND (
174
+ ${flattenedContext
175
+ .map(([key, value]) => {
176
+ return `(plr.attribute = ? AND plr.value @> ?)`;
139
177
  })
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);
178
+ .join(" OR ")}
179
+ )
180
+ ) = (
181
+ /* Get total rule count */
182
+ SELECT COUNT(*)
183
+ FROM price_list_rule plr
184
+ WHERE plr.price_list_id = pl.id
185
+ AND plr.deleted_at IS NULL
186
+ )
187
+ )
188
+ `, flattenedContext.flatMap(([key, value]) => {
189
+ return [key, JSON.stringify(Array.isArray(value) ? value : [value])];
190
+ }));
191
+ query.where((qb) => {
192
+ qb.whereNull("price.price_list_id")
193
+ .andWhereRaw(priceRuleConditions)
194
+ .orWhere((qb2) => {
195
+ qb2
196
+ .whereNotNull("price.price_list_id")
197
+ .whereRaw(priceListRuleConditions)
198
+ .andWhereRaw(priceRuleConditions);
167
199
  });
168
200
  });
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
201
  }
200
202
  else {
201
- priceSetQueryKnex.andWhere(function () {
202
- this.andWhere("price.min_quantity", "<=", "1").orWhereNull("price.min_quantity");
203
+ // Simple case - just get prices with no rules or price lists with no rules
204
+ query.where(function () {
205
+ this.where("price.rules_count", 0).orWhere(function () {
206
+ this.whereNotNull("price.price_list_id").where("pl.rules_count", 0);
207
+ });
203
208
  });
204
209
  }
205
- return await priceSetQueryKnex;
210
+ // Optimized ordering to help query planner and preserve price list precedence
211
+ query
212
+ .orderByRaw("price.price_list_id IS NOT NULL DESC")
213
+ .orderByRaw("price.rules_count + COALESCE(pl.rules_count, 0) DESC") // More specific rules first
214
+ .orderBy("pl.id", "asc") // Order by price list ID to ensure first created price list takes precedence
215
+ .orderBy("price.amount", "asc"); // For non-price list prices, cheaper ones first
216
+ // Execute the optimized query
217
+ return await query;
206
218
  }
207
219
  }
208
220
  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,E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,YAAY,CAAC,qBAAqB,CAAC;yBACnC,QAAQ,CAAC,uBAAuB,CAAC;yBACjC,WAAW,CAAC,mBAAmB,CAAC,CAAA;gBACrC,CAAC,CAAC,CAAA;YACN,CAAC,CAAC,CAAA;QACJ,CAAC;aAAM,CAAC;YACN,2EAA2E;YAC3E,KAAK,CAAC,KAAK,CAAC;gBACV,IAAI,CAAC,KAAK,CAAC,mBAAmB,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;oBAGzC,IAAI,CAAC,YAAY,CAAC,qBAAqB,CAAC,CAAC,KAAK,CAAC,gBAAgB,EAAE,CAAC,CAAC,CAAA;gBACrE,CAAC,CAAC,CAAA;YACJ,CAAC,CAAC,CAAA;QACJ,CAAC;QAED,8EAA8E;QAC9E,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;CACF;AA9PD,8CA8PC"}
@@ -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/migrations/Migration20250409122219.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-20250409125618",
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-20250409125618",
40
+ "@medusajs/test-utils": "3.0.0-snapshot-20250409125618",
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-20250409125618",
54
54
  "@mikro-orm/core": "6.4.3",
55
55
  "@mikro-orm/migrations": "6.4.3",
56
56
  "@mikro-orm/postgresql": "6.4.3",