Skip to content

Commit

Permalink
refactor: fix small perf issues found by oxlint
Browse files Browse the repository at this point in the history
  • Loading branch information
B4nan committed Mar 17, 2024
1 parent a30112c commit 8799461
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/entity/ArrayCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class ArrayCollection<T extends object, O extends object> {
}

const meta = this.property.targetMeta!;
const args = [...meta.toJsonParams.map(() => undefined)];
const args = meta.toJsonParams.map(() => undefined);

return this.map(item => wrap(item as TT).toJSON(...args));
}
Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/entity/EntityLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,10 @@ export class EntityLoader {
if (prop.kind === ReferenceKind.ONE_TO_MANY) {
children.push(...filtered.map(e => (e[prop.name] as unknown as Collection<Entity, AnyEntity>).owner));
} else if (prop.kind === ReferenceKind.MANY_TO_MANY && prop.owner) {
children.push(...filtered.reduce((a, b) => [...a, ...(b[prop.name] as unknown as Collection<AnyEntity>).getItems()], [] as AnyEntity[]));
children.push(...filtered.reduce((a, b) => {
a.push(...(b[prop.name] as Collection<AnyEntity>).getItems());
return a;
}, [] as AnyEntity[]));
} else if (prop.kind === ReferenceKind.MANY_TO_MANY) { // inverse side
children.push(...filtered as AnyEntity[]);
} else { // MANY_TO_ONE or ONE_TO_ONE
Expand Down
2 changes: 1 addition & 1 deletion packages/knex/src/query/ObjectCriteriaNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export class ObjectCriteriaNode<T extends object> extends CriteriaNode<T> {
if (Utils.isOperator(k, false)) {
const tmp = payload[k];
delete payload[k];
o[this.aliased(field, alias)] = { [k]: tmp, ...(o[this.aliased(field, alias)] || {}) };
o[this.aliased(field, alias)] = { [k]: tmp, ...o[this.aliased(field, alias)] };
} else if (this.isPrefixed(k) || Utils.isOperator(k) || !childAlias) {
const idx = prop.referencedPKs.indexOf(k as EntityKey);
const key = idx !== -1 && !childAlias && ![ReferenceKind.ONE_TO_MANY, ReferenceKind.MANY_TO_MANY].includes(prop.kind) ? prop.joinColumns[idx] : k;
Expand Down
2 changes: 1 addition & 1 deletion packages/mongodb/src/MongoConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export class MongoConnection extends Connection {
const options: Dictionary = ctx ? { session: ctx } : {};

if (fields) {
options.projection = fields.reduce((o, k) => ({ ...o, [k]: 1 }), {});
options.projection = fields.reduce((o, k) => Object.assign(o, { [k]: 1 }), {});
}

const resultSet = this.getCollection<T>(collection).find(where as Filter<T>, options);
Expand Down
4 changes: 2 additions & 2 deletions packages/mongodb/src/MongoSchemaGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export class MongoSchemaGenerator extends AbstractSchemaGenerator<MongoDriver> {
res.push([collection.collectionName, collection.createIndex(fieldOrSpec, {
name: index.name,
unique: false,
...(index.options || {}),
...index.options,
})]);
});

Expand All @@ -196,7 +196,7 @@ export class MongoSchemaGenerator extends AbstractSchemaGenerator<MongoDriver> {
res.push([collection.collectionName, collection.createIndex(fieldOrSpec, {
name: index.name,
unique: true,
...(index.options || {}),
...index.options,
})]);
});

Expand Down

0 comments on commit 8799461

Please sign in to comment.