ecoCode icon indicating copy to clipboard operation
ecoCode copied to clipboard

Crjvm205

Open AntoineMeheut opened this issue 1 year ago • 17 comments

CRJVM205 - Force the use of FetchType LAZY on collections in Entity JPA

  • Team: 17%
  • Analyzed language: java
  • Implemented rule: search in the java code for FetchTypes for which the developer has not set LAZY in order to avoid unnecessarily loading data clusters into memory.
  • Result of this rule: reduce the amount of useless data loaded into memory, to reduce the consumption of RAM and therefore of electricity.
  • Unit tests: passed
  • Definition of done : test in sonarqube passed with ecoCode-java-test-project and we did a merge request of the tests in ecoCode-java-test-project

Pitch : Consider using LAZY mode on your FetchType for collections in JPA type entities. This will reduce the amount of data loaded into memory. And having less data loaded into memory reduces power consumption. Any electricity not produced is good for our planet.

AntoineMeheut avatar Apr 05 '23 15:04 AntoineMeheut

Sorry, but we didn't see in the rules that we had to increment the number of rules in this control, it's done

AntoineMeheut avatar Apr 05 '23 19:04 AntoineMeheut

Just for information, 3 PR on the same rule : https://github.com/green-code-initiative/ecoCode/pull/125 https://github.com/green-code-initiative/ecoCode/pull/155

MP-Aubay avatar Apr 06 '23 13:04 MP-Aubay

Hi @dirdr, please take into account remaining review notes and correct the code small raised by sonarcloud.io thank you.

dedece35 avatar May 09 '23 13:05 dedece35

code review fix ok

dirdr avatar May 17 '23 06:05 dirdr

This PR has been automatically marked as stale because it has no activity for 30 days. Please add a comment if you want to keep the issue open. Thank you for your contributions!

github-actions[bot] avatar Jun 26 '23 02:06 github-actions[bot]

Any news ?

dirdr avatar Jun 27 '23 08:06 dirdr

Hi @dirdr, no, I didn't work on this PR, sorry. Once current task is over, this is my next priority ... with two others CRJVM205 JIRAs :p

dedece35 avatar Jul 03 '23 13:07 dedece35

This PR has been automatically marked as stale because it has no activity for 30 days. Please add a comment if you want to keep the issue open. Thank you for your contributions!

github-actions[bot] avatar Aug 03 '23 02:08 github-actions[bot]

Hi @dirdr, sorry there is another conflict to resolve, please. and then, check DoD list here : https://github.com/green-code-initiative/ecoCode-common/blob/main/doc/starter-pack.md#definition-of-done-of-a-pr

dedece35 avatar Sep 22 '23 14:09 dedece35

This PR has been automatically marked as stale because it has no activity for 30 days. Please add a comment if you want to keep the issue open. Thank you for your contributions!

github-actions[bot] avatar Oct 25 '23 02:10 github-actions[bot]

PR on java-test-project : https://github.com/green-code-initiative/ecoCode-java-test-project/pull/5

dedece35 avatar Dec 15 '23 15:12 dedece35

to discuss in core-team :

  • good argument to prove it's a "green" rule
  • no native Sonarqube rule found

but I think we can't force developers not to use EAGER key word if they really need it.

do we refuse this rule or not ?

dedece35 avatar Jan 01 '24 21:01 dedece35

Hello,

we do not force the user to not use "EAGER", it is just a code smell. He can always ignore it. The true question is, when we use JPA entities, is the "EAGER" keyword a classic use? If in 90% of the case its use is justified may be we should not raise the code smell to avoid to pollute the analysis. However, I think this rule is specific enough to not raise too much (not like a problem we had with a rule on Exceptions) and I think it is not a bad thing to throw the code smell because as I understand the rule, the usage of "EAGER" must be done in specific justified cases.

jhertout avatar Jan 03 '24 07:01 jhertout

This PR has been automatically marked as stale because it has no activity for 60 days. Please add a comment if you want to keep the issue open. Thank you for your contributions!

github-actions[bot] avatar Mar 04 '24 02:03 github-actions[bot]