@mikro-orm/knex 6.1.13-dev.29 → 6.1.13-dev.30

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.
@@ -30,6 +30,7 @@ class MsSqlTableCompiler extends MonkeyPatchable_1.MonkeyPatchable.MsSqlTableCom
30
30
  });
31
31
  }
32
32
  dropForeign(columns, constraintName) {
33
+ /* istanbul ignore next */
33
34
  constraintName = constraintName
34
35
  ? this.formatter.wrap(constraintName)
35
36
  : this._indexCommand('foreign', this.tableNameRaw, columns);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/knex",
3
- "version": "6.1.13-dev.29",
3
+ "version": "6.1.13-dev.30",
4
4
  "description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
5
5
  "main": "index.js",
6
6
  "module": "index.mjs",
@@ -66,6 +66,6 @@
66
66
  "@mikro-orm/core": "^6.1.12"
67
67
  },
68
68
  "peerDependencies": {
69
- "@mikro-orm/core": "6.1.13-dev.29"
69
+ "@mikro-orm/core": "6.1.13-dev.30"
70
70
  }
71
71
  }
@@ -973,7 +973,7 @@ class QueryBuilder {
973
973
  }
974
974
  }
975
975
  for (const f of Object.keys(this._populateMap)) {
976
- if (type === 'where') {
976
+ if (type === 'where' && this._joins[f]) {
977
977
  const cols = this.helper.mapJoinColumns(this.type ?? enums_1.QueryType.SELECT, this._joins[f]);
978
978
  for (const col of cols) {
979
979
  ret.push(col);
@@ -1238,6 +1238,27 @@ class QueryBuilder {
1238
1238
  subSubQuery.__raw = true; // tag it as there is now way to check via `instanceof`
1239
1239
  this._limit = undefined;
1240
1240
  this._offset = undefined;
1241
+ // remove joins that are not used for population or ordering to improve performance
1242
+ const populate = new Set();
1243
+ const orderByAliases = this._orderBy
1244
+ .flatMap(hint => Object.keys(hint))
1245
+ .map(k => k.split('.')[0]);
1246
+ function addPath(hints, prefix = '') {
1247
+ for (const hint of hints) {
1248
+ const field = hint.field.split(':')[0];
1249
+ populate.add((prefix ? prefix + '.' : '') + field);
1250
+ if (hint.children) {
1251
+ addPath(hint.children, (prefix ? prefix + '.' : '') + field);
1252
+ }
1253
+ }
1254
+ }
1255
+ addPath(this._populate);
1256
+ for (const [key, join] of Object.entries(this._joins)) {
1257
+ const path = join.path?.replace(/\[populate]|\[pivot]|:ref/g, '').replace(new RegExp(`^${meta.className}.`), '');
1258
+ if (!populate.has(path ?? '') && !orderByAliases.includes(join.alias)) {
1259
+ delete this._joins[key];
1260
+ }
1261
+ }
1241
1262
  this.select(this._fields).where({ [core_1.Utils.getPrimaryKeyHash(meta.primaryKeys)]: { $in: subSubQuery } });
1242
1263
  }
1243
1264
  wrapModifySubQuery(meta) {