Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: reduce cognitive complexity #401

Merged
merged 18 commits into from
Aug 10, 2024

Conversation

jean-michelet
Copy link
Contributor

@jean-michelet jean-michelet commented Jul 26, 2024

This PR is intended to reduce the overall cognitive complexity of the component, which is imho unnecessarily hard to read, although I understand this is subjective. Basically, I've done a bit of refactoring, breaking down huge functions into smaller ones and limiting the use of nested closures.

I put the findPlugins function in its own file to reduce the size of index.js and because it is a clearly separated step.

I tried to do the same with loadPlugins but vitest failed to transpile after that... But the two big steps are finding and loading, registering is just a few lines so I think it's ok.

I think I've also slightly reduced algorithmic complexity by making a single global iteration on pluginTree, including plugin loading, hooks and registration. This also makes it possible to benefit from the current iteration context, instead of making distinct tree traversal for hooks and plugins, although this point isn't quite clear to me yet. So it's not a fix of #383.

@jean-michelet jean-michelet marked this pull request as draft July 26, 2024 12:26
@jean-michelet jean-michelet marked this pull request as ready for review July 26, 2024 14:49
@jean-michelet jean-michelet changed the title [WIP] feat: reduce cognitive complexity feat: reduce cognitive complexity Jul 26, 2024
@jean-michelet jean-michelet requested review from Uzlopak and removed request for gurgunday July 27, 2024 07:55
find-plugins.js Outdated Show resolved Hide resolved
find-plugins.js Outdated Show resolved Hide resolved
find-plugins.js Outdated Show resolved Hide resolved
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@jean-michelet
Copy link
Contributor Author

Just look for my last commit plz, I had missed a previous optimization during refactorisation.

Copy link
Member

@gurgunday gurgunday left a comment

Choose a reason for hiding this comment

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

LGTM

@gurgunday
Copy link
Member

gurgunday commented Jul 29, 2024

Can you update the workflow to v5.0.0?

uses: fastify/workflows/.github/workflows/[email protected]

@jean-michelet
Copy link
Contributor Author

I do it in an independent PR @gurgunday : #403

@jean-michelet
Copy link
Contributor Author

I would prefer a review from @climba03003 before merging.

@jean-michelet
Copy link
Contributor Author

Can you review @climba03003 plz or can we merge?

Copy link
Member

@climba03003 climba03003 left a comment

Choose a reason for hiding this comment

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

LGTM.

@jean-michelet jean-michelet merged commit 688199d into fastify:master Aug 10, 2024
14 checks passed
@jean-michelet jean-michelet deleted the refactoring branch August 10, 2024 06:26
@jean-michelet jean-michelet mentioned this pull request Aug 25, 2024
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants