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

Crjvm205 #122

Open
wants to merge 47 commits into
base: main
Choose a base branch
from
Open

Conversation

AntoineMeheut
Copy link
Contributor

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.

@dirdr
Copy link

dirdr commented May 17, 2023

code review fix ok

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

93.4% 93.4% Coverage
0.0% 0.0% Duplication

@github-actions
Copy link

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 github-actions bot added the stale label Jun 26, 2023
@dirdr
Copy link

dirdr commented Jun 27, 2023

Any news ?

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

93.4% 93.4% Coverage
0.0% 0.0% Duplication

@github-actions github-actions bot removed the stale label Jun 28, 2023
@dedece35
Copy link
Member

dedece35 commented Jul 3, 2023

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

@github-actions
Copy link

github-actions bot commented Aug 3, 2023

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!

@dedece35
Copy link
Member

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

@github-actions
Copy link

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 github-actions bot added the stale label Oct 25, 2023
* OneToOne: Eager
* reporting the issues if necessary
*/
private void performsCheck(Arguments arguments, AnnotationTree annotationTree, Tree tree) {
Copy link
Member

Choose a reason for hiding this comment

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

here, no need to give arguments as input parameter because it already is present inside annotationTree input parameter


import java.util.List;

@Rule(key = "EC80", name = "Developpement",
Copy link
Member

Choose a reason for hiding this comment

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

there is a new way to declare configuration of one rule : please see other rules as example

@@ -0,0 +1,16 @@
{
"title": "Force the use of FetchType LAZY on collections in Entity JPA",
Copy link
Member

Choose a reason for hiding this comment

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

now, it isn't the good way to declare rule properties but inside ecocode-rules-specifications (please see another rule as example)


@Column(name = "ORDER", length = 50, nullable = false, unique = false)
private Set<OrderItem> items = new HashSet<OrderItem>();

Copy link
Member

Choose a reason for hiding this comment

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

please as a new use case with default value for fetch keywork (thus, without "fetch" variable assigned)

import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

Copy link
Member

Choose a reason for hiding this comment

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

why don't you give all use cases in a single file ? why several test files ?

@@ -30,7 +30,7 @@ void checkNumberRules() {
final JavaCheckRegistrar registrar = new JavaCheckRegistrar();
registrar.register(context);

assertThat(context.checkClasses()).hasSize(19);
assertThat(context.checkClasses()).hasSize(20);
Copy link
Member

Choose a reason for hiding this comment

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

maybe value has to be changed. to recheck locally, please

@dedece35
Copy link
Member

@dedece35
Copy link
Member

dedece35 commented Jan 1, 2024

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 ?

@jhertout
Copy link
Contributor

jhertout commented Jan 3, 2024

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.

Copy link

github-actions bot commented Mar 4, 2024

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 github-actions bot added the stale label Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants