Optimize metadata queries (#7013)
In this PR: 1. Refactor guards to avoid duplicated queries: WorkspaceAuthGuard and UserAuthGuard only check for existence of workspace and user in the request without querying the database
This commit is contained in:
committed by
Charles Bochet
parent
cf8b1161cc
commit
523df5398a
@ -1,11 +1,11 @@
|
||||
import { UseGuards } from '@nestjs/common';
|
||||
import { Resolver, Mutation, Query } from '@nestjs/graphql';
|
||||
import { Mutation, Query, Resolver } from '@nestjs/graphql';
|
||||
|
||||
import { PostgresCredentialsDTO } from 'src/engine/core-modules/postgres-credentials/dtos/postgres-credentials.dto';
|
||||
import { PostgresCredentialsService } from 'src/engine/core-modules/postgres-credentials/postgres-credentials.service';
|
||||
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
||||
import { AuthWorkspace } from 'src/engine/decorators/auth/auth-workspace.decorator';
|
||||
import { JwtAuthGuard } from 'src/engine/guards/jwt.auth.guard';
|
||||
import { WorkspaceAuthGuard } from 'src/engine/guards/workspace-auth.guard';
|
||||
|
||||
@Resolver(() => PostgresCredentialsDTO)
|
||||
export class PostgresCredentialsResolver {
|
||||
@ -13,19 +13,19 @@ export class PostgresCredentialsResolver {
|
||||
private readonly postgresCredentialsService: PostgresCredentialsService,
|
||||
) {}
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@UseGuards(WorkspaceAuthGuard)
|
||||
@Mutation(() => PostgresCredentialsDTO)
|
||||
async enablePostgresProxy(@AuthWorkspace() { id: workspaceId }: Workspace) {
|
||||
return this.postgresCredentialsService.enablePostgresProxy(workspaceId);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@UseGuards(WorkspaceAuthGuard)
|
||||
@Mutation(() => PostgresCredentialsDTO)
|
||||
async disablePostgresProxy(@AuthWorkspace() { id: workspaceId }: Workspace) {
|
||||
return this.postgresCredentialsService.disablePostgresProxy(workspaceId);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@UseGuards(WorkspaceAuthGuard)
|
||||
@Query(() => PostgresCredentialsDTO, { nullable: true })
|
||||
async getPostgresCredentials(
|
||||
@AuthWorkspace() { id: workspaceId }: Workspace,
|
||||
|
||||
Reference in New Issue
Block a user