Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions redisinsight/api/src/common/constants/recommendations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@ export const COMBINE_SMALL_STRINGS_TO_HASHES_RECOMMENDATION_MEMORY = 200;
export const USE_SMALLER_KEYS_RECOMMENDATION_TOTAL = 1_000_000;
export const COMPRESS_HASH_FIELD_NAMES_RECOMMENDATION_LENGTH = 1000;
export const COMPRESSION_FOR_LIST_RECOMMENDATION_LENGTH = 1000;
export const BIG_SETS_RECOMMENDATION_LENGTH = 100_000;
export const BIG_SETS_RECOMMENDATION_LENGTH = 1_000;
export const BIG_AMOUNT_OF_CONNECTED_CLIENTS_RECOMMENDATION_CLIENTS = 100;
export const BIG_STRINGS_RECOMMENDATION_MEMORY = 1_000_000;
export const BIG_STRINGS_RECOMMENDATION_MEMORY = 100_000;
export const RTS_RECOMMENDATION_PERCENTAGE = 99;
export const SEARCH_INDEXES_RECOMMENDATION_KEYS_FOR_CHECK = 100;
export const REDIS_VERSION_RECOMMENDATION_VERSION = '6';
export const COMBINE_SMALL_STRINGS_TO_HASHES_RECOMMENDATION_KEYS_COUNT = 50;
export const INTEGERS_IN_SET_RECOMMENDATION_MEMBERS_FOR_CHECK = 50;
export const COMBINE_SMALL_STRINGS_TO_HASHES_RECOMMENDATION_KEYS_COUNT = 10;
export const SEARCH_HASH_RECOMMENDATION_KEYS_FOR_CHECK = 50;
export const SEARCH_HASH_RECOMMENDATION_KEYS_LENGTH = 2;
2 changes: 0 additions & 2 deletions redisinsight/api/src/constants/recommendations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export const RECOMMENDATION_NAMES = Object.freeze({
REDIS_VERSION: 'redisVersion',
SEARCH_INDEXES: 'searchIndexes',
SEARCH_JSON: 'searchJSON',
INTEGERS_IN_SET: 'integersInSets',
STRING_TO_JSON: 'stringToJson',
SEARCH_VISUALIZATION: 'searchVisualization',
SEARCH_HASH: 'searchHash',
Expand All @@ -38,6 +37,5 @@ export const REDIS_STACK = [
RECOMMENDATION_NAMES.REDIS_VERSION,
RECOMMENDATION_NAMES.SEARCH_INDEXES,
RECOMMENDATION_NAMES.SEARCH_JSON,
RECOMMENDATION_NAMES.INTEGERS_IN_SET,
RECOMMENDATION_NAMES.STRING_TO_JSON,
]
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
mockRedisNoPermError,
mockRedisWrongTypeError,
mockBrowserClientMetadata,
mockDatabaseRecommendationService,
} from 'src/__mocks__';
import { ReplyError } from 'src/models';
import {
Expand All @@ -24,8 +23,6 @@ import {
mockGetSetMembersDto, mockGetSetMembersResponse,
mockSetMembers,
} from 'src/modules/browser/__mocks__';
import { DatabaseRecommendationService } from 'src/modules/database-recommendation/database-recommendation.service';
import { RECOMMENDATION_NAMES } from 'src/constants';
import { SetBusinessService } from './set-business.service';
import {
CreateSetWithExpireDto,
Expand All @@ -39,7 +36,6 @@ nodeClient.isCluster = false;
describe('SetBusinessService', () => {
let service: SetBusinessService;
let browserTool;
let recommendationService;

beforeEach(async () => {
jest.clearAllMocks();
Expand All @@ -51,16 +47,11 @@ describe('SetBusinessService', () => {
provide: BrowserToolService,
useFactory: mockRedisConsumer,
},
{
provide: DatabaseRecommendationService,
useFactory: mockDatabaseRecommendationService,
},
],
}).compile();

service = module.get<SetBusinessService>(SetBusinessService);
browserTool = module.get<BrowserToolService>(BrowserToolService);
recommendationService = module.get<DatabaseRecommendationService>(DatabaseRecommendationService);
});

describe('createSet', () => {
Expand Down Expand Up @@ -326,32 +317,6 @@ describe('SetBusinessService', () => {
service.getMembers(mockBrowserClientMetadata, mockGetSetMembersDto),
).rejects.toThrow(ForbiddenException);
});
it('should call recommendationService', async () => {
when(browserTool.execCommand)
.calledWith(
mockBrowserClientMetadata,
BrowserToolSetCommands.SScan,
expect.anything(),
)
.mockResolvedValue([Buffer.from('0'), mockSetMembers]);

const result = await service.getMembers(
mockBrowserClientMetadata,
mockGetSetMembersDto,
);
expect(recommendationService.check).toBeCalledWith(
mockBrowserClientMetadata,
RECOMMENDATION_NAMES.INTEGERS_IN_SET,
{
members: result.members,
keyName: result.keyName,
client: nodeClient,
databaseId: mockBrowserClientMetadata.databaseId,
},
);

expect(recommendationService.check).toBeCalledTimes(1);
});
});

describe('addMembers', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
Logger,
NotFoundException,
} from '@nestjs/common';
import { RECOMMENDATION_NAMES, RedisErrorCodes } from 'src/constants';
import { RedisErrorCodes } from 'src/constants';
import ERROR_MESSAGES from 'src/constants/error-messages';
import config from 'src/utils/config';
import {
Expand All @@ -17,7 +17,6 @@ import {
BrowserToolKeysCommands,
BrowserToolSetCommands,
} from 'src/modules/browser/constants/browser-tool-commands';
import { DatabaseRecommendationService } from 'src/modules/database-recommendation/database-recommendation.service';
import { plainToClass } from 'class-transformer';
import {
AddMembersToSetDto,
Expand All @@ -38,7 +37,6 @@ export class SetBusinessService {

constructor(
private browserTool: BrowserToolService,
private recommendationService: DatabaseRecommendationService,
) {}

public async createSet(
Expand Down Expand Up @@ -81,7 +79,6 @@ export class SetBusinessService {
clientMetadata: ClientMetadata,
dto: GetSetMembersDto,
): Promise<GetSetMembersResponse> {
const client = await this.browserTool.getRedisClient(clientMetadata);
this.logger.log('Getting members of the Set data type stored at key.');
const { keyName } = dto;
let result: GetSetMembersResponse = {
Expand Down Expand Up @@ -120,16 +117,6 @@ export class SetBusinessService {
const scanResult = await this.scanSet(clientMetadata, dto);
result = { ...result, ...scanResult };
}
this.recommendationService.check(
clientMetadata,
RECOMMENDATION_NAMES.INTEGERS_IN_SET,
{
members: result.members,
keyName,
client,
databaseId: clientMetadata.databaseId,
},
);
this.logger.log('Succeed to get members of the Set data type.');
return plainToClass(GetSetMembersResponse, result);
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
SearchJSONStrategy,
BigSetStrategy,
RTSStrategy,
IntegersInSetStrategy,
AvoidLogicalDatabasesStrategy,
ShardHashStrategy,
StringToJsonStrategy,
Expand Down Expand Up @@ -44,7 +43,6 @@ describe('RecommendationProvider', () => {
[RECOMMENDATION_NAMES.REDIS_VERSION, new RedisVersionStrategy()],
[RECOMMENDATION_NAMES.BIG_SETS, new BigSetStrategy()],
[RECOMMENDATION_NAMES.RTS, new RTSStrategy()],
[RECOMMENDATION_NAMES.INTEGERS_IN_SET, new IntegersInSetStrategy()],
[RECOMMENDATION_NAMES.AVOID_LOGICAL_DATABASES, new AvoidLogicalDatabasesStrategy()],
[RECOMMENDATION_NAMES.BIG_HASHES, new ShardHashStrategy()],
[RECOMMENDATION_NAMES.STRING_TO_JSON, new StringToJsonStrategy()],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
SearchJSONStrategy,
BigSetStrategy,
RTSStrategy,
IntegersInSetStrategy,
AvoidLogicalDatabasesStrategy,
ShardHashStrategy,
StringToJsonStrategy,
Expand All @@ -35,7 +34,6 @@ export class RecommendationProvider {
this.strategies.set(RECOMMENDATION_NAMES.SEARCH_JSON, new SearchJSONStrategy(databaseService));
this.strategies.set(RECOMMENDATION_NAMES.BIG_SETS, new BigSetStrategy());
this.strategies.set(RECOMMENDATION_NAMES.RTS, new RTSStrategy());
this.strategies.set(RECOMMENDATION_NAMES.INTEGERS_IN_SET, new IntegersInSetStrategy());
this.strategies.set(RECOMMENDATION_NAMES.AVOID_LOGICAL_DATABASES, new AvoidLogicalDatabasesStrategy());
this.strategies.set(RECOMMENDATION_NAMES.BIG_HASHES, new ShardHashStrategy());
this.strategies.set(RECOMMENDATION_NAMES.STRING_TO_JSON, new StringToJsonStrategy());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ const mockSetInfo: GetKeyInfoResponse = {
type: 'set',
ttl: -1,
size: 1,
length: 100_000,
length: 1_000,
};

const mockBigSetInfo: GetKeyInfoResponse = {
name: Buffer.from('string2'),
type: 'set',
ttl: -1,
size: 1,
length: 100_001,
length: 1_001,
};

const mockHashInfo: GetKeyInfoResponse = {
Expand All @@ -33,15 +33,15 @@ describe('BigSetStrategy', () => {
});

describe('isRecommendationReached', () => {
it('should return false when set length < 100 000', async () => {
it('should return false when set length < 1 000', async () => {
expect(await strategy.isRecommendationReached(mockSetInfo)).toEqual({ isReached: false });
});

it('should return false when not set key', async () => {
expect(await strategy.isRecommendationReached(mockHashInfo)).toEqual({ isReached: false });
});

it('should return true when set length > 100 000', async () => {
it('should return true when set length > 1 000', async () => {
expect(await strategy.isRecommendationReached(mockBigSetInfo))
.toEqual({ isReached: true, params: { keys: [mockBigSetInfo.name] } });
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export * from './search-JSON.strategy';
export * from './big-set.strategy';
export * from './rts.strategy';
export * from './avoid-logical-databases.strategy';
export * from './integer-in-set.strategy';
export * from './shard-hash.strategy';
export * from './string-to-json.strategy';
export * from './search-visualization.strategy';
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const mockBigStringKey = {
};

const mockHugeStringKey = {
name: Buffer.from('name'), type: 'string', length: 10, memory: 1_000_001, ttl: -1,
name: Buffer.from('name'), type: 'string', length: 10, memory: 100_001, ttl: -1,
};

const mockHugeStringKey1 = {
Expand All @@ -89,7 +89,7 @@ const mockBigSet = {
};

const mockHugeSet = {
name: Buffer.from('name'), type: 'set', length: 100_001, memory: 10, ttl: -1,
name: Buffer.from('name'), type: 'set', length: 1_001, memory: 10, ttl: -1,
};

const mockBigZSetKey = {
Expand Down Expand Up @@ -214,18 +214,18 @@ describe('RecommendationProvider', () => {
describe('determineCombineSmallStringsToHashesRecommendation', () => {
it('should not return combineSmallStringsToHashes recommendation', async () => {
const smallStringRecommendation = await service.determineCombineSmallStringsToHashesRecommendation(
new Array(49).fill(mockSmallStringKey),
new Array(9).fill(mockSmallStringKey),
);
expect(smallStringRecommendation).toEqual(null);
});
it('should not return combineSmallStringsToHashes recommendation when strings are big', async () => {
const smallStringRecommendation = await service.determineCombineSmallStringsToHashesRecommendation(
new Array(50).fill(mockBigStringKey),
new Array(10).fill(mockBigStringKey),
);
expect(smallStringRecommendation).toEqual(null);
});
it('should return combineSmallStringsToHashes recommendation', async () => {
const smallStringRecommendation = await service.determineCombineSmallStringsToHashesRecommendation(new Array(50).fill(mockSmallStringKey));
const smallStringRecommendation = await service.determineCombineSmallStringsToHashesRecommendation(new Array(10).fill(mockSmallStringKey));
expect(smallStringRecommendation)
.toEqual({
name: RECOMMENDATION_NAMES.COMBINE_SMALL_STRINGS_TO_HASHES,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,6 @@ export class RecommendationService {
RECOMMENDATION_NAMES.STRING_TO_JSON,
() => null,
],
[
RECOMMENDATION_NAMES.INTEGERS_IN_SET,
() => null,
],
[
RECOMMENDATION_NAMES.SEARCH_JSON,
async () => await this.recommendationProvider.determineSearchJSONRecommendation(keys, indexes),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ describe('POST /databases/:instanceId/analysis', () => {
statusCode: 201,
responseSchema,
before: async () => {
await rte.data.generateHugeNumberOfTinyStringKeys(50);
await rte.data.generateHugeNumberOfTinyStringKeys(10);
},
checkFn: async ({ body }) => {
// can not predict keys order, params.keys is random
Expand Down Expand Up @@ -533,7 +533,7 @@ describe('POST /databases/:instanceId/analysis', () => {
statusCode: 201,
responseSchema,
before: async () => {
const BIG_STRING_MEMORY = 5_000_001;
const BIG_STRING_MEMORY = 100_001;
const bigStringValue = Buffer.alloc(BIG_STRING_MEMORY, 'a').toString();

await rte.data.sendCommand('set', [constants.TEST_STRING_KEY_1, bigStringValue]);
Expand Down Expand Up @@ -577,7 +577,7 @@ describe('POST /databases/:instanceId/analysis', () => {
statusCode: 201,
responseSchema,
before: async () => {
const NUMBERS_OF_SET_MEMBERS = 100_001;
const NUMBERS_OF_SET_MEMBERS = 1_001;
await rte.data.generateHugeNumberOfMembersForSetKey(NUMBERS_OF_SET_MEMBERS, true);
},
checkFn: async ({ body }) => {
Expand Down
Loading