perf(core): Cache roles (#6803)

* refactor: Create `RoleService`

* refactor: Refactor to use service

* refactor: Move `getUserRoleForWorkflow`

* refactor: Clear out old `RoleService`

* refactor: Consolidate utils into service

* refactor: Remove unused methods

* test: Add tests

* refactor: Remove redundant return types

* refactor: Missing utility

* chore: Remove commented out bit

* refactor: Make `Db.collections.Repository` inaccessible

* chore: Cleanup

* feat: Prepopulate cache

* chore: Remove logging

* fix: Account for tests where roles are undefined

* fix: Restore `prettier.prettierPath`

* test: Account for cache enabled and disabled

* fix: Restore `Role` in `Db.collections`

* refactor: Simplify by removing `orFail`

* refactor: Rename for clarity

* refactor: Use `cacheKey` for readability

* refactor: Validate role before creation

* refacator: Remove redundant `cache` prefix

* ci: Lint fix

* test: Fix e2e
This commit is contained in:
Iván Ovejero
2023-08-03 08:58:36 +02:00
committed by GitHub
parent f93270abd5
commit e4f041815a
33 changed files with 280 additions and 214 deletions

View File

@@ -3,8 +3,8 @@ import { Not } from 'typeorm';
import * as Db from '@/Db';
import type { CredentialsEntity } from '@db/entities/CredentialsEntity';
import { User } from '@db/entities/User';
import { RoleRepository } from '@db/repositories';
import { BaseCommand } from '../BaseCommand';
import { RoleService } from '@/services/role.service';
const defaultUserProps = {
firstName: null,
@@ -21,8 +21,8 @@ export class Reset extends BaseCommand {
async run(): Promise<void> {
const owner = await this.getInstanceOwner();
const ownerWorkflowRole = await Container.get(RoleRepository).findWorkflowOwnerRoleOrFail();
const ownerCredentialRole = await Container.get(RoleRepository).findCredentialOwnerRoleOrFail();
const ownerWorkflowRole = await Container.get(RoleService).findWorkflowOwnerRole();
const ownerCredentialRole = await Container.get(RoleService).findCredentialOwnerRole();
await Db.collections.SharedWorkflow.update(
{ userId: Not(owner.id), roleId: ownerWorkflowRole.id },
@@ -60,7 +60,7 @@ export class Reset extends BaseCommand {
}
async getInstanceOwner(): Promise<User> {
const globalRole = await Container.get(RoleRepository).findGlobalOwnerRoleOrFail();
const globalRole = await Container.get(RoleService).findGlobalOwnerRole();
const owner = await Db.collections.User.findOneBy({ globalRoleId: globalRole.id });