Skip to content

Commit a9dd41c

Browse files
author
arthosofteq
authored
Merge pull request #1418 from RedisInsight/be/bugfix/RI-3816-multiple_workbench_clients
#RI-3816 prevent creating redis client for each command in the pipeli…
2 parents f2d3621 + 8608dbe commit a9dd41c

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

redisinsight/api/src/modules/workbench/workbench.service.spec.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Test, TestingModule } from '@nestjs/testing';
22
import { v4 as uuidv4 } from 'uuid';
33
import { when } from 'jest-when';
4-
import { mockDatabase, mockWorkbenchAnalyticsService } from 'src/__mocks__';
4+
import { mockDatabase, mockDatabaseConnectionService, mockWorkbenchAnalyticsService } from 'src/__mocks__';
55
import { IFindRedisClientInstanceByOptions } from 'src/modules/redis/redis.service';
66
import { WorkbenchService } from 'src/modules/workbench/workbench.service';
77
import { WorkbenchCommandsExecutor } from 'src/modules/workbench/providers/workbench-commands.executor';
@@ -17,6 +17,7 @@ import { CommandExecutionResult } from 'src/modules/workbench/models/command-exe
1717
import { CommandExecutionStatus } from 'src/modules/cli/dto/cli.dto';
1818
import { BadRequestException, InternalServerErrorException } from '@nestjs/common';
1919
import ERROR_MESSAGES from 'src/constants/error-messages';
20+
import { DatabaseConnectionService } from 'src/modules/database/database-connection.service';
2021
import { CreateCommandExecutionsDto } from 'src/modules/workbench/dto/create-command-executions.dto';
2122
import { WorkbenchAnalyticsService } from './services/workbench-analytics/workbench-analytics.service';
2223

@@ -126,6 +127,10 @@ describe('WorkbenchService', () => {
126127
provide: CommandExecutionProvider,
127128
useFactory: mockCommandExecutionProvider,
128129
},
130+
{
131+
provide: DatabaseConnectionService,
132+
useFactory: mockDatabaseConnectionService,
133+
},
129134
],
130135
}).compile();
131136

redisinsight/api/src/modules/workbench/workbench.service.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@ import { getBlockingCommands, multilineCommandToOneLine } from 'src/utils/cli-he
1010
import ERROR_MESSAGES from 'src/constants/error-messages';
1111
import { ShortCommandExecution } from 'src/modules/workbench/models/short-command-execution';
1212
import { CommandExecutionStatus } from 'src/modules/cli/dto/cli.dto';
13+
import { DatabaseConnectionService } from 'src/modules/database/database-connection.service';
14+
import { AppTool } from 'src/models';
1315
import { getUnsupportedCommands } from './utils/getUnsupportedCommands';
1416
import { WorkbenchAnalyticsService } from './services/workbench-analytics/workbench-analytics.service';
1517

1618
@Injectable()
1719
export class WorkbenchService {
1820
constructor(
21+
private readonly databaseConnectionService: DatabaseConnectionService,
1922
private commandsExecutor: WorkbenchCommandsExecutor,
2023
private commandExecutionProvider: CommandExecutionProvider,
2124
private analyticsService: WorkbenchAnalyticsService,
@@ -127,6 +130,13 @@ export class WorkbenchService {
127130
clientOptions: IFindRedisClientInstanceByOptions,
128131
dto: CreateCommandExecutionsDto,
129132
): Promise<CommandExecution[]> {
133+
// todo: handle concurrent client creation on RedisModule side
134+
// temporary workaround. Just create client before any command execution precess
135+
await this.databaseConnectionService.getOrCreateClient({
136+
databaseId: clientOptions.instanceId,
137+
namespace: AppTool.Workbench,
138+
});
139+
130140
if (dto.resultsMode === ResultsMode.GroupMode) {
131141
return this.commandExecutionProvider.createMany(
132142
[await this.createCommandsExecution(clientOptions, dto, dto.commands)],

0 commit comments

Comments
 (0)