mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
ci(core): Reduce memory usage in tests (part-2) (no-changelog) (#7671)
This also gets rid of `Db.collection`, which was another source of circular dependencies.
This commit is contained in:
committed by
GitHub
parent
37dd658dc5
commit
000e76e3b4
@@ -1,10 +1,14 @@
|
||||
import { Container } from 'typedi';
|
||||
import { Not } from 'typeorm';
|
||||
import * as Db from '@/Db';
|
||||
import type { CredentialsEntity } from '@db/entities/CredentialsEntity';
|
||||
import { User } from '@db/entities/User';
|
||||
import { BaseCommand } from '../BaseCommand';
|
||||
import { CredentialsRepository } from '@db/repositories/credentials.repository';
|
||||
import { SettingsRepository } from '@db/repositories/settings.repository';
|
||||
import { SharedCredentialsRepository } from '@db/repositories/sharedCredentials.repository';
|
||||
import { SharedWorkflowRepository } from '@db/repositories/sharedWorkflow.repository';
|
||||
import { UserRepository } from '@db/repositories/user.repository';
|
||||
import { RoleService } from '@/services/role.service';
|
||||
import { BaseCommand } from '../BaseCommand';
|
||||
|
||||
const defaultUserProps = {
|
||||
firstName: null,
|
||||
@@ -24,34 +28,34 @@ export class Reset extends BaseCommand {
|
||||
const ownerWorkflowRole = await Container.get(RoleService).findWorkflowOwnerRole();
|
||||
const ownerCredentialRole = await Container.get(RoleService).findCredentialOwnerRole();
|
||||
|
||||
await Db.collections.SharedWorkflow.update(
|
||||
await Container.get(SharedWorkflowRepository).update(
|
||||
{ userId: Not(owner.id), roleId: ownerWorkflowRole.id },
|
||||
{ user: owner },
|
||||
);
|
||||
|
||||
await Db.collections.SharedCredentials.update(
|
||||
await Container.get(SharedCredentialsRepository).update(
|
||||
{ userId: Not(owner.id), roleId: ownerCredentialRole.id },
|
||||
{ user: owner },
|
||||
);
|
||||
|
||||
await Db.collections.User.delete({ id: Not(owner.id) });
|
||||
await Db.collections.User.save(Object.assign(owner, defaultUserProps));
|
||||
await Container.get(UserRepository).delete({ id: Not(owner.id) });
|
||||
await Container.get(UserRepository).save(Object.assign(owner, defaultUserProps));
|
||||
|
||||
const danglingCredentials: CredentialsEntity[] =
|
||||
await Db.collections.Credentials.createQueryBuilder('credentials')
|
||||
.leftJoinAndSelect('credentials.shared', 'shared')
|
||||
.where('shared.credentialsId is null')
|
||||
.getMany();
|
||||
const danglingCredentials: CredentialsEntity[] = await Container.get(CredentialsRepository)
|
||||
.createQueryBuilder('credentials')
|
||||
.leftJoinAndSelect('credentials.shared', 'shared')
|
||||
.where('shared.credentialsId is null')
|
||||
.getMany();
|
||||
const newSharedCredentials = danglingCredentials.map((credentials) =>
|
||||
Db.collections.SharedCredentials.create({
|
||||
Container.get(SharedCredentialsRepository).create({
|
||||
credentials,
|
||||
user: owner,
|
||||
role: ownerCredentialRole,
|
||||
}),
|
||||
);
|
||||
await Db.collections.SharedCredentials.save(newSharedCredentials);
|
||||
await Container.get(SharedCredentialsRepository).save(newSharedCredentials);
|
||||
|
||||
await Db.collections.Settings.update(
|
||||
await Container.get(SettingsRepository).update(
|
||||
{ key: 'userManagement.isInstanceOwnerSetUp' },
|
||||
{ value: 'false' },
|
||||
);
|
||||
@@ -62,7 +66,7 @@ export class Reset extends BaseCommand {
|
||||
async getInstanceOwner(): Promise<User> {
|
||||
const globalRole = await Container.get(RoleService).findGlobalOwnerRole();
|
||||
|
||||
const owner = await Db.collections.User.findOneBy({ globalRoleId: globalRole.id });
|
||||
const owner = await Container.get(UserRepository).findOneBy({ globalRoleId: globalRole.id });
|
||||
|
||||
if (owner) return owner;
|
||||
|
||||
@@ -70,9 +74,9 @@ export class Reset extends BaseCommand {
|
||||
|
||||
Object.assign(user, { ...defaultUserProps, globalRole });
|
||||
|
||||
await Db.collections.User.save(user);
|
||||
await Container.get(UserRepository).save(user);
|
||||
|
||||
return Db.collections.User.findOneByOrFail({ globalRoleId: globalRole.id });
|
||||
return Container.get(UserRepository).findOneByOrFail({ globalRoleId: globalRole.id });
|
||||
}
|
||||
|
||||
async catch(error: Error): Promise<void> {
|
||||
|
||||
Reference in New Issue
Block a user