|
1 | 1 | import { Injectable } from '@nestjs/common';
|
2 | 2 | import { Redis, Cluster } from 'ioredis';
|
| 3 | +import { difference } from 'lodash'; |
3 | 4 | import { RecommendationProvider } from 'src/modules/recommendation/providers/recommendation.provider';
|
4 | 5 | import { Recommendation } from 'src/modules/database-analysis/models/recommendation';
|
5 | 6 | import { RECOMMENDATION_NAMES } from 'src/constants';
|
@@ -38,27 +39,88 @@ export class RecommendationService {
|
38 | 39 | exclude,
|
39 | 40 | } = dto;
|
40 | 41 |
|
| 42 | + const recommendations = new Map([ |
| 43 | + [ |
| 44 | + RECOMMENDATION_NAMES.LUA_SCRIPT, |
| 45 | + async () => await this.recommendationProvider.determineLuaScriptRecommendation(client), |
| 46 | + ], |
| 47 | + [ |
| 48 | + RECOMMENDATION_NAMES.BIG_HASHES, |
| 49 | + async () => await this.recommendationProvider.determineBigHashesRecommendation(keys), |
| 50 | + ], |
| 51 | + [ |
| 52 | + RECOMMENDATION_NAMES.USE_SMALLER_KEYS, |
| 53 | + async () => await this.recommendationProvider.determineBigTotalRecommendation(total), |
| 54 | + ], |
| 55 | + [ |
| 56 | + RECOMMENDATION_NAMES.AVOID_LOGICAL_DATABASES, |
| 57 | + async () => await this.recommendationProvider.determineLogicalDatabasesRecommendation(client), |
| 58 | + ], |
| 59 | + [ |
| 60 | + RECOMMENDATION_NAMES.COMBINE_SMALL_STRINGS_TO_HASHES, |
| 61 | + async () => await this.recommendationProvider.determineCombineSmallStringsToHashesRecommendation(keys), |
| 62 | + ], |
| 63 | + [ |
| 64 | + RECOMMENDATION_NAMES.INCREASE_SET_MAX_INTSET_ENTRIES, |
| 65 | + async () => await this.recommendationProvider.determineIncreaseSetMaxIntsetEntriesRecommendation(client, keys), |
| 66 | + ], |
| 67 | + [ |
| 68 | + RECOMMENDATION_NAMES.HASH_HASHTABLE_TO_ZIPLIST, |
| 69 | + async () => await this.recommendationProvider.determineHashHashtableToZiplistRecommendation(client, keys), |
| 70 | + ], |
| 71 | + [ |
| 72 | + RECOMMENDATION_NAMES.COMPRESS_HASH_FIELD_NAMES, |
| 73 | + async () => await this.recommendationProvider.determineCompressHashFieldNamesRecommendation(keys), |
| 74 | + ], |
| 75 | + [ |
| 76 | + RECOMMENDATION_NAMES.COMPRESSION_FOR_LIST, |
| 77 | + async () => await this.recommendationProvider.determineCompressionForListRecommendation(keys), |
| 78 | + ], |
| 79 | + [ |
| 80 | + RECOMMENDATION_NAMES.BIG_STRINGS, |
| 81 | + async () => await this.recommendationProvider.determineBigStringsRecommendation(keys), |
| 82 | + ], |
| 83 | + [ |
| 84 | + RECOMMENDATION_NAMES.ZSET_HASHTABLE_TO_ZIPLIST, |
| 85 | + async () => await this.recommendationProvider.determineZSetHashtableToZiplistRecommendation(client, keys), |
| 86 | + ], |
| 87 | + [ |
| 88 | + RECOMMENDATION_NAMES.BIG_SETS, |
| 89 | + async () => await this.recommendationProvider.determineBigSetsRecommendation(keys), |
| 90 | + ], |
| 91 | + [ |
| 92 | + RECOMMENDATION_NAMES.BIG_AMOUNT_OF_CONNECTED_CLIENTS, |
| 93 | + async () => await this.recommendationProvider.determineConnectionClientsRecommendation(client), |
| 94 | + ], |
| 95 | + [ |
| 96 | + RECOMMENDATION_NAMES.RTS, |
| 97 | + async () => await this.recommendationProvider.determineRTSRecommendation(client, keys), |
| 98 | + ], |
| 99 | + [ |
| 100 | + RECOMMENDATION_NAMES.REDIS_SEARCH, |
| 101 | + async () => await this.recommendationProvider.determineRediSearchRecommendation(client, keys), |
| 102 | + ], |
| 103 | + [ |
| 104 | + RECOMMENDATION_NAMES.REDIS_VERSION, |
| 105 | + async () => await this.recommendationProvider.determineRedisVersionRecommendation(client), |
| 106 | + ], |
| 107 | + [ |
| 108 | + RECOMMENDATION_NAMES.SEARCH_INDEXES, |
| 109 | + async () => await this.recommendationProvider.determineSearchIndexesRecommendation(client, keys, globalClient), |
| 110 | + ], |
| 111 | + [ |
| 112 | + RECOMMENDATION_NAMES.DANGEROUS_COMMANDS, |
| 113 | + async () => await this.recommendationProvider.determineDangerousCommandsRecommendation(client), |
| 114 | + ], |
| 115 | + [ |
| 116 | + RECOMMENDATION_NAMES.SET_PASSWORD, |
| 117 | + async () => await this.recommendationProvider.determineSetPasswordRecommendation(client), |
| 118 | + ], |
| 119 | + ]); |
| 120 | + |
| 121 | + const recommendationsToDetermine = difference(Object.values(RECOMMENDATION_NAMES), exclude); |
| 122 | + |
41 | 123 | return (
|
42 |
| - Promise.all([ |
43 |
| - await this.recommendationProvider.determineLuaScriptRecommendation(client), |
44 |
| - await this.recommendationProvider.determineBigHashesRecommendation(keys), |
45 |
| - await this.recommendationProvider.determineBigTotalRecommendation(total), |
46 |
| - await this.recommendationProvider.determineLogicalDatabasesRecommendation(client), |
47 |
| - await this.recommendationProvider.determineCombineSmallStringsToHashesRecommendation(keys), |
48 |
| - await this.recommendationProvider.determineIncreaseSetMaxIntsetEntriesRecommendation(client, keys), |
49 |
| - await this.recommendationProvider.determineHashHashtableToZiplistRecommendation(client, keys), |
50 |
| - await this.recommendationProvider.determineCompressHashFieldNamesRecommendation(keys), |
51 |
| - await this.recommendationProvider.determineCompressionForListRecommendation(keys), |
52 |
| - await this.recommendationProvider.determineBigStringsRecommendation(keys), |
53 |
| - await this.recommendationProvider.determineZSetHashtableToZiplistRecommendation(client, keys), |
54 |
| - await this.recommendationProvider.determineBigSetsRecommendation(keys), |
55 |
| - await this.recommendationProvider.determineConnectionClientsRecommendation(client), |
56 |
| - // TODO rework, need better solution to do not start determine recommendation |
57 |
| - exclude.includes(RECOMMENDATION_NAMES.RTS) ? null : await this.recommendationProvider.determineRTSRecommendation(client, keys), |
58 |
| - await this.recommendationProvider.determineRediSearchRecommendation(client, keys), |
59 |
| - await this.recommendationProvider.determineRedisVersionRecommendation(client), |
60 |
| - await this.recommendationProvider.determineSearchIndexesRecommendation(client, keys, globalClient), |
61 |
| - await this.recommendationProvider.determineSetPasswordRecommendation(client), |
62 |
| - ])); |
| 124 | + Promise.all(recommendationsToDetermine.map((recommendation) => recommendations.get(recommendation)()))); |
63 | 125 | }
|
64 | 126 | }
|
0 commit comments