Skip to content

Conversation

AmirAllayarovSofteq
Copy link
Contributor

@AmirAllayarovSofteq AmirAllayarovSofteq commented Nov 10, 2022

RI-3527 - add luaScript recommendation
RI-3565 - add use smaller keys recommendation
RI-3566 - add big hashes recommendation

@AmirAllayarovSofteq AmirAllayarovSofteq added the feature New feature or request label Nov 10, 2022
@AmirAllayarovSofteq AmirAllayarovSofteq self-assigned this Nov 10, 2022
import { DatabaseRecommendationsModule } from 'src/modules/db-recommendations/database-recommendations.module';

@Module({
imports: [DatabaseRecommendationsModule],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is better to use the same names pattern for module and everything inside. e.g.

  1. DatabaseRecommendationsModule, DatabaseRecommendationsService, etc OR
  2. RecommendationsModule and RecommendationsService, etc.

or you can mix these names in case when you will create general RecommendationModule which might have database recommendations or some other kind of recommendations. So it might be nice to have RecommendationsModule and DatabaseRecommendationsService inside

throw new NotFoundException(ERROR_MESSAGES.DATABASE_ANALYSIS_NOT_FOUND);
}

console.log(classToClass(DatabaseAnalysis, await this.decryptEntity(entity, true)))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oO :)

databaseId: clientOptions.instanceId,
...dto,
progress,
recommendations: await this.recommendationsService.getRecommendations(clientOptions),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like such implementation for calculating recommendations. Current implementation is suitable for any recommendations based on info. What you are planning to do with this for other types of recommendations which should use keys analysis? (fetch again N keys?)
this implementation does fit current requirements for lua. so you, probably could go with this for now but this should be reworked a lot with next tasks related to recommendations

return get(info, 'memory.number_of_cached_scripts', {});
}));

return max(await nodesNumbersOfCachedScripts) > minNumberOfCachedScripts;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like to do extra calls to Redis server since we already did it few seconds ago for other purpose. This is not critical but may be if you rework entire solution (see comment above) how we are calculating recommendations these unnecessary calls might be removed at all.

egor-zalenski
egor-zalenski previously approved these changes Nov 11, 2022
Copy link
Collaborator

@ArtemHoruzhenko ArtemHoruzhenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BE looks much better. Well done
However, please, finalize PR. Seems like this is more like a draft rather then prepared one.

// redis client (or info)
// constructor(
// private readonly databaseConnectionService: DatabaseConnectionService,
// ) {}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please, remove commented lines here

public async getRecommendations(
redisClient: Redis,
// { client?, keys?, info?, etc }
// clientOptions: IFindRedisClientInstanceByOptions,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here

new Command('info', ['memory'], { replyEncoding: 'utf8' }),
) as string,
);
const nodesNumbersOfCachedScripts = get(info, 'memory.number_of_cached_scripts', {});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{} by default?

);
const nodesNumbersOfCachedScripts = get(info, 'memory.number_of_cached_scripts', {});

return parseInt(await nodesNumbersOfCachedScripts, 10) < minNumberOfCachedScripts;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

await for what?

// ) as string,
// );
// return get(info, 'memory.number_of_cached_scripts', {});
// }));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here

}

@Injectable()
export class RecommendationService {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you already have the same logic in the provider?

new Command('info', ['memory'], { replyEncoding: 'utf8' }),
) as string,
);
const nodesNumbersOfCachedScripts = get(info, 'memory.number_of_cached_scripts', {});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same as above

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AmirAllayarovSofteq Again, why default value is empty object here? Please, explain or fix it, do not ignore
get(info, 'memory.number_of_cached_scripts', {})

);
const nodesNumbersOfCachedScripts = get(info, 'memory.number_of_cached_scripts', {});

return checkIsGreaterThan(minNumberOfCachedScripts, parseInt(await nodesNumbersOfCachedScripts, 10));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same as above

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AmirAllayarovSofteq Why await here?

Copy link
Collaborator

@ArtemHoruzhenko ArtemHoruzhenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks very good! I like how it implemented now.
However I have few concerns here:

  1. Weak tests. I did't see (correct me if I'm wrong) tests for recommendation creation (.eq(0) only). When we must check that it is created and stored encrypted.
  2. Please, address all comments before next review request. Reviewers might be wrong and it is normal to add your own comments if you don't agree with them and you are not going to change anything. Please do not ignore them. Review process itself might take a time and concentration. So I assume I have to go through your changes again, for this PR...

new Command('info', ['memory'], { replyEncoding: 'utf8' }),
) as string,
);
const nodesNumbersOfCachedScripts = get(info, 'memory.number_of_cached_scripts', {});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AmirAllayarovSofteq Again, why default value is empty object here? Please, explain or fix it, do not ignore
get(info, 'memory.number_of_cached_scripts', {})

);
const nodesNumbersOfCachedScripts = get(info, 'memory.number_of_cached_scripts', {});

return checkIsGreaterThan(minNumberOfCachedScripts, parseInt(await nodesNumbersOfCachedScripts, 10));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AmirAllayarovSofteq Why await here?

const { client, keys, info } = dto;
const recommendations = [];
if (await this.recommendationProvider.determineLuaScriptRecommendation(client)) {
recommendations.push({ name: 'luaScript' });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not something to implement right now but in the future if we want to have more fields inside recommendation (e.g. current value of cached scripts) to show it inside recommendation box on UI, it might be better whendetermineLuaScriptRecommendation method returns Recommendation model or null rather then boolean. May be refactor this with the next recommendations implementation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will think about it

export const checkIsGreaterThan = (
conditionNumber: number,
currentCount: number,
): boolean => currentCount > conditionNumber;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we need this method? Do you plan to have custom logic inside? Do you plan to have a method for each possible condition???

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arthosofteq We discussed this, there was a plan to separate the method into a function that takes cached_scripts_condition and current_cached_scripts and a function to calculate current_cached_scripts

AmirAllayarovSofteq and others added 19 commits January 16, 2023 19:50
…ndations_message

#RI-4023 - update no recommendations message
…ndation_voting

#RI-3977 - add recommendation voting
…ndation_voting

#RI-3977 - add recommendation voting
Delete unused nth from verifyVoteDisabled
Refactor for page objects
…ecommendations

Feature/ri 3971 3572 add recommendations
Add comments to methods
…endation_voting

E2e/feature/ri 3977 recommendation voting
@vlad-dargel vlad-dargel self-requested a review January 24, 2023 11:58
vlad-dargel
vlad-dargel previously approved these changes Jan 24, 2023
…tion_voting

Feature/ri 3977 recommendation voting
@vlad-dargel vlad-dargel self-requested a review January 24, 2023 13:08
@vlad-dargel vlad-dargel merged commit 02eb496 into main Jan 24, 2023
@vlad-dargel vlad-dargel deleted the feature/RI-3527_lua_scripts branch January 24, 2023 13:10
@vlad-dargel vlad-dargel restored the feature/RI-3527_lua_scripts branch January 24, 2023 14:30
@vlad-dargel vlad-dargel deleted the feature/RI-3527_lua_scripts branch January 24, 2023 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants