From 481e369337739aaed94fed6c1de93fcf7f3237d2 Mon Sep 17 00:00:00 2001 From: Luc Fouin Date: Thu, 30 May 2024 12:18:26 +0200 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=E2=9C=A8=20Implementing=20EC24=20f?= =?UTF-8?q?or=20Java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #308 --- RULES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RULES.md b/RULES.md index 05310c4b..f809d9be 100644 --- a/RULES.md +++ b/RULES.md @@ -37,7 +37,7 @@ Some are applicable for different technologies. | EC12 | Modify several CSS properties all at once | ESLint key : @ecocode/no-multiple-style-changes /// type : Front-end | | 🚫 | ❓ | βœ… | 🚫 | 🚫 | ❓ | 🚫 | | EC13 | Prefer API collections with pagination | ESLint key : @ecocode/prefer-collections-with-pagination /// type : Back-end | | ❓ | ❓ | βœ… | ❓ | ❓ | ❓ | 🚫 | | EC22 | The use of methods for basic operations | Using methods for basic operations consumes additional system resources. The interpreter must in effect and solve the objects and then the methods, just to carry out these simple operations of the language. | [cnumr best practices (3rd edition) BP_048 (no longer exists in edition 4)](https://www.greenit.fr/2019/05/07/ecoconception-web-les-115-bonnes-pratiques-3eme-edition/) | 🚫 | 🚫 | πŸš€ | πŸš€ | πŸš€ | 🚫 | 🚫 | -| EC24 | Limit the number of returns for a SQL query | ESLint key : @ecocode/limit-db-query-results /// type : Back-end | | βœ… | πŸš€ | βœ… | πŸš€ | πŸš€ | πŸš€ | 🚫 | +| EC24 | Limit the number of returns for a SQL query | ESLint key : @ecocode/limit-db-query-results /// type : Back-end | | 🚧 | πŸš€ | βœ… | πŸš€ | πŸš€ | πŸš€ | 🚫 | | EC25 | Do not use an image with empty source attribute | ESLint key : @ecocode/no-empty-image-src-attribute /// type : Front-end | | ❓ | ❓ | βœ… | ❓ | ❓ | ❓ | πŸš€ | | EC26 | Prefer shorthand CSS notations | ESLint key : @ecocode/prefer-shorthand-css-notations /// type : Front-end | | ❓ | ❓ | βœ… | ❓ | ❓ | ❓ | 🚫 | | EC27 | Usage of system.arraycopy to copy arrays | Programs spend most of the time in loops. These can be resource consuming, especially when they integrate heavy processing (IO access). Moreover, the size of the data and processing inside the loops will not allow full use of hardware mechanisms such as the cache or compiler optimization mechanisms. | | βœ… | 🚫 | 🚫 | 🚫 | 🚫 | 🚫 | 🚫 | From 54091924f8c844215c6880869abb663cc42c25cb Mon Sep 17 00:00:00 2001 From: Luc Fouin Date: Thu, 30 May 2024 14:07:10 +0200 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20=E2=9C=A8=20Implementing=20EC24?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit EC24 was not yet implemented in Java Fixes #308 --- CHANGELOG.md | 2 ++ .../src/main/rules/EC24/EC24.json | 1 + .../src/main/rules/EC24/java/EC24.asciidoc | 34 +++++++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 ecocode-rules-specifications/src/main/rules/EC24/java/EC24.asciidoc diff --git a/CHANGELOG.md b/CHANGELOG.md index 21a7ee4b..b9cb182a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- [#308](https://github.com/green-code-initiative/ecoCode/issues/308) Implementing EC24 in Java + ### Changed ### Deleted diff --git a/ecocode-rules-specifications/src/main/rules/EC24/EC24.json b/ecocode-rules-specifications/src/main/rules/EC24/EC24.json index d1577a12..10804174 100644 --- a/ecocode-rules-specifications/src/main/rules/EC24/EC24.json +++ b/ecocode-rules-specifications/src/main/rules/EC24/EC24.json @@ -20,6 +20,7 @@ ], "defaultSeverity": "Major", "compatibleLanguages": [ + "JAVA", "JAVASCRIPT", "TYPESCRIPT" ] diff --git a/ecocode-rules-specifications/src/main/rules/EC24/java/EC24.asciidoc b/ecocode-rules-specifications/src/main/rules/EC24/java/EC24.asciidoc new file mode 100644 index 00000000..51140247 --- /dev/null +++ b/ecocode-rules-specifications/src/main/rules/EC24/java/EC24.asciidoc @@ -0,0 +1,34 @@ +:!sectids: + +== Why is this an issue? + +SQL queries often involve processing large amounts of data, and fetching a large number of rows can consume significant CPU resources. +By limiting the number of rows returned, you reduce the amount of processing that needs to be done by the database engine, which in turn lowers CPU consumption. + +Transmitting a large number of rows over a network can be resource-intensive. +By restricting the result set size, you reduce the amount of data that needs to be transferred between the database and the application, improving network efficiency. + +If you store data about customers, you certainly don’t need to retrieve information of all at once, because the larger the table will be, the more elements the query will return. + +[source,java,data-diff-id="1",data-diff-type="noncompliant"] +---- +String query = "SELECT * FROM customers"; // Non-compliant +---- + +It may therefore be a good idea to limit the results and use pagination, for example. + +[source,java,data-diff-id="1",data-diff-type="compliant"] +---- +String query = "SELECT id,name,email FROM customers FETCH FIRST 10 ROWS ONLY"; // Compliant +---- + +== Resources + +=== Documentation + +- https://dev.mysql.com/doc/refman/8.0/en/limit-optimization.html[MySQL Reference Manual] - LIMIT Query Optimization +- https://www.postgresql.org/docs/current/queries-limit.html[PostgreSQL: Documentation] - LIMIT and OFFSET + +=== Articles & blog posts + +- https://www.oreilly.com/library/view/high-performance-mysql/9780596101718/ch04.html[Query Performance Optimization]