Skip to content

Create a simple unoptimized DB call#1

Merged
KaranSinghG merged 7 commits into
mainfrom
develop
Jun 20, 2026
Merged

Create a simple unoptimized DB call#1
KaranSinghG merged 7 commits into
mainfrom
develop

Conversation

@KaranSinghG

@KaranSinghG KaranSinghG commented Jun 20, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features

    • Initialized a new Spring Boot application with sample order and customer data automatically populated on startup.
    • Added /orders/all REST API endpoint to retrieve all orders with response time tracking.
  • Documentation

    • Updated performance baseline documentation with separate metrics for small and large unoptimized datasets, including endpoint latency and database query counts.
  • Chores

    • Added project build configuration and Maven wrapper setup for standardized builds.

… add OrderRepository for fetching orders with customers
- Update README with performance baselines for small and large datasets
- Refactor OrderController to log query execution time
- Modify Customer entity to include ID generation strategy
- Remove unnecessary query method from OrderRepository
- Add SeedDataCreator for populating initial data
- Create CustomerRepository for customer data management
@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@KaranSinghG, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 52 minutes and 31 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7046b0c2-8821-41fa-9ef4-30fafff67a7f

📥 Commits

Reviewing files that changed from the base of the PR and between 726c343 and 0005823.

📒 Files selected for processing (1)
  • README.md
📝 Walkthrough

Walkthrough

This PR introduces an entirely new Spring Boot project (sqlOptimization) for demonstrating SQL latency optimization. It adds Maven wrapper scripts (mvnw, mvnw.cmd), a pom.xml targeting Spring Boot 4.1.0 and Java 21, JPA entities (Customer, Order) with repositories, a startup seed data runner creating 1,000 customers with 20 orders each, a REST controller with a timed /orders/all endpoint, and updated README performance baselines for small and large datasets.

Changes

SQL Optimization Demo — New Spring Boot Project

Layer / File(s) Summary
Maven wrapper, build config, and git setup
.gitattributes, .gitignore, .mvn/wrapper/maven-wrapper.properties, pom.xml, mvnw, mvnw.cmd
.gitattributes and .gitignore configure line endings and artifact exclusions. pom.xml defines the Spring Boot 4.1.0 / Java 21 project with web, JPA, H2, and test dependencies. mvnw and mvnw.cmd implement full Maven distribution bootstrapping (download, hash-based caching, SHA-256 validation, credential support) for Unix and Windows.
JPA entities and repositories
src/main/java/com/demo/sqlOptimization/entities/Customer.java, src/main/java/com/demo/sqlOptimization/entities/Order.java, src/main/java/com/demo/sqlOptimization/repository/CustomerRepository.java, src/main/java/com/demo/sqlOptimization/repository/OrderRepository.java
Customer maps to customers with a @OneToMany orders association. Order maps to orders with a @ManyToOne back-reference to Customer and @JsonIgnoreProperties to break circular serialization. Both repositories extend JpaRepository with no additional methods.
Application entry point, seed data, and REST controller
src/main/java/com/demo/sqlOptimization/SqlOptimizationApplication.java, src/main/java/com/demo/sqlOptimization/SeedDataCreator.java, src/main/java/com/demo/sqlOptimization/controller/OrderController.java, src/main/resources/application.yaml
SqlOptimizationApplication boots the app. SeedDataCreator is a CommandLineRunner that creates 1,000 customers × 20 orders if the database is empty. OrderController exposes GET /orders/test and GET /orders/all, with the latter measuring and printing query duration via System.currentTimeMillis().
Context-load test and README performance baselines
src/test/java/com/demo/sqlOptimization/SqlOptimizationApplicationTests.java, README.md
Adds a @SpringBootTest smoke test verifying the context loads. README replaces a single incomplete baseline with two entries: small dataset (83 ms avg) and large dataset (7.06 s avg) for GET /api/orders/all.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐇 Hopped into an empty repo one day,
Planted some entities, watched Spring bloom away.
One thousand customers, twenty orders each neat,
The /orders/all endpoint now times every feat.
From mvnw scripts to H2 in-mem bliss —
A SQL demo born with a cottontail's kiss! 🌱

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the primary objective of the changeset: creating a basic unoptimized database call endpoint and supporting infrastructure for performance testing.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch develop

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.mvn/wrapper/maven-wrapper.properties:
- Around line 1-3: The maven-wrapper.properties file is missing a checksum
property for integrity verification. Since Maven 3.9.16 only publishes SHA-512
checksums and not SHA-256, add the distributionSha512Sum property with the
provided checksum value to the file. Additionally, update the Maven wrapper
scripts (typically in the .mvn/wrapper directory) to support SHA-512
verification instead of SHA-256 to ensure the integrity check functions properly
with the new checksum type.

In `@README.md`:
- Around line 6-16: The README.md file contains endpoint and formatting errors
in the Performance Baseline sections. The endpoints listed as `/api/orders/all`
in both the Unoptimized-Data-small and Unoptimized-Data-large sections should be
corrected to `/orders/all` to match the actual controller implementation.
Additionally, the data volume in the Unoptimized-Data-large section shows an
incorrectly formatted number `2000,000` which should be corrected to `2,000,000`
to use proper comma notation for the 2 million orders.

In `@src/main/java/com/demo/sqlOptimization/controller/OrderController.java`:
- Around line 29-35: The getAllOrders() method in OrderController is loading all
orders into memory using unbounded findAll() which causes performance
degradation with large datasets. Refactor this endpoint to implement pagination
by adding a Pageable parameter to the getAllOrders() method signature, update
the orderRepository.findAll() call to pass the Pageable parameter, and change
the return type from List<Order> to Page<Order> to properly handle paginated
results.

In `@src/main/java/com/demo/sqlOptimization/SeedDataCreator.java`:
- Around line 14-30: The SeedDataCreator class is missing profile gating which
causes it to run in all environments including tests. Add the `@Profile`("demo")
annotation to the SeedDataCreator class definition (above the `@Component`
annotation) to ensure the component is only instantiated when the "demo" profile
is active, preventing seed data injection in test environments while keeping the
existing count guard as a secondary safety measure.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 260db271-e824-4f7a-9d8e-62c62bfadd9e

📥 Commits

Reviewing files that changed from the base of the PR and between 41b6292 and 726c343.

📒 Files selected for processing (16)
  • .gitattributes
  • .gitignore
  • .mvn/wrapper/maven-wrapper.properties
  • README.md
  • mvnw
  • mvnw.cmd
  • pom.xml
  • src/main/java/com/demo/sqlOptimization/SeedDataCreator.java
  • src/main/java/com/demo/sqlOptimization/SqlOptimizationApplication.java
  • src/main/java/com/demo/sqlOptimization/controller/OrderController.java
  • src/main/java/com/demo/sqlOptimization/entities/Customer.java
  • src/main/java/com/demo/sqlOptimization/entities/Order.java
  • src/main/java/com/demo/sqlOptimization/repository/CustomerRepository.java
  • src/main/java/com/demo/sqlOptimization/repository/OrderRepository.java
  • src/main/resources/application.yaml
  • src/test/java/com/demo/sqlOptimization/SqlOptimizationApplicationTests.java

Comment on lines +1 to +3
wrapperVersion=3.3.4
distributionType=only-script
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.16/apache-maven-3.9.16-bin.zip

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

props=".mvn/wrapper/maven-wrapper.properties"

echo "Checking for distributionSha256Sum..."
if awk -F= '$1=="distributionSha256Sum"{found=1} END{exit !found}' "$props"; then
  echo "distributionSha256Sum is present"
else
  echo "distributionSha256Sum is missing"
fi

url="$(awk -F= '$1=="distributionUrl"{print $2}' "$props")"
echo "distributionUrl=$url"

echo "Expected SHA-256 from repository:"
curl -fsSL "${url}.sha256"

Repository: KaranSinghG/sql-latency-optimization-demo

Length of output: 376


🌐 Web query:

Apache Maven 3.9.16 SHA-256 checksum distribution source

💡 Result:

The official distribution of Apache Maven 3.9.16 provides SHA-512 checksum files, not SHA-256 checksum files [1][2]. You can verify the integrity of your download using the provided.sha512 files located in the binaries and source directories on the official Apache distribution server [1][3][2]. For each distribution archive, the corresponding.sha512 file is available at the same location [1][2]: - Binary (tar.gz): apache-maven-3.9.16-bin.tar.gz.sha512 [1][2] - Binary (zip): apache-maven-3.9.16-bin.zip.sha512 [1][2] - Source (tar.gz): apache-maven-3.9.16-src.tar.gz.sha512 [3] - Source (zip): apache-maven-3.9.16-src.zip.sha512 [3] While Apache documentation indicates that SHA-256 hashes can be generated manually using tools like gpg or certUtil if needed [4], the project distributes SHA-512 hashes as the standard for verifying these release bundles [1][2]. You should always download these files from the official Apache Maven download location to ensure integrity [5][4].

Citations:


🏁 Script executed:

#!/bin/bash
# Check if Maven publishes checksums in alternate locations
# Try Apache Maven dist folder
echo "Checking Apache Maven dist folder..."
curl -fsSL "https://archive.apache.org/dist/maven/maven-3/3.9.16/apache-maven-3.9.16-bin.zip.sha256" 2>&1 | head -20

Repository: KaranSinghG/sql-latency-optimization-demo

Length of output: 171


🌐 Web query:

Maven wrapper configuration distributionSha512Sum property supported

💡 Result:

Yes, the distributionSha512Sum property is supported in Maven Wrapper. It was introduced to address the need for SHA-512 verification, as the Apache Maven project primarily publishes SHA-512 checksums for its distributions [1][2][3]. The property can be added to the maven-wrapper.properties file to verify the integrity of the downloaded Maven distribution [1]. Alongside it, a corresponding wrapperSha512Sum property was also introduced to allow verification of the maven-wrapper.jar file itself [1][3]. These properties were added to provide a more practical alternative to the SHA-256 checksums, which are still supported for backward compatibility but are not always readily published by the Maven project [1][4][3].

Citations:


🏁 Script executed:

#!/bin/bash
# Fetch the actual SHA-512 checksum from official Apache Maven repository
echo "Fetching SHA-512 checksum from Apache Maven dist..."
curl -fsSL "https://downloads.apache.org/maven/maven-3/3.9.16/binaries/apache-maven-3.9.16-bin.zip.sha512"

echo ""
echo "Checking if wrapper supports distributionSha512Sum..."
grep -r "distributionSha512Sum\|distributionSha256Sum" . 2>/dev/null || echo "No references found in repo"

Repository: KaranSinghG/sql-latency-optimization-demo

Length of output: 1945


🌐 Web query:

Maven wrapper version 3.3.4 changelog SHA-512 support release date

💡 Result:

Apache Maven Wrapper version 3.3.4 was released on September 8, 2025 [1]. While the 3.3.4 release primarily served as a "quickfix" release to revert an unwanted commit from the previous version [2][3], the addition of SHA-512 checksum support was introduced via pull request #398 [4], which was integrated into the Apache Maven Wrapper codebase. This feature allows users to utilize distributionSha512Sum and wrapperSha512Sum properties in their maven-wrapper.properties file for integrity verification [4][5]. Key details regarding SHA-512 support: - Purpose: It was implemented because the Apache Maven project officially publishes SHA-512 checksums for its distributions, making them more accessible than the previously required SHA-256 sums [4][6]. - Functionality: The wrapper scripts (shell and PowerShell) and the Java runtime were updated to validate downloaded artifacts using these new SHA-512 properties, while maintaining backward compatibility with SHA-256 [4][5]. - Documentation: Checksum verification instructions are available on the official Apache Maven Wrapper tools site [7][4].

Citations:


🏁 Script executed:

#!/bin/bash
# Check wrapper version history and when SHA-512 was introduced
echo "Checking Maven wrapper GitHub for version 3.3.4 and SHA-512 support..."
curl -fsSL "https://api.github.com/repos/apache/maven-wrapper/releases" | jq '.[] | select(.tag_name | contains("3.3")) | {tag_name, published_at}' | head -40

Repository: KaranSinghG/sql-latency-optimization-demo

Length of output: 566


🏁 Script executed:

#!/bin/bash
# Check if maven-wrapper files were properly updated for version 3.3.4
echo "Checking maven-wrapper.jar version..."
ls -lh .mvn/wrapper/maven-wrapper.jar 2>/dev/null || echo "No jar found"

echo ""
echo "Checking if mvnw script references SHA-512..."
grep -c "distributionSha512Sum" ./mvnw 2>/dev/null || echo "distributionSha512Sum not found in mvnw"

echo ""
echo "Comparing with official Maven wrapper..."
# Check what the official wrapper generates
curl -fsSL "https://raw.githubusercontent.com/apache/maven-wrapper/master/mvnw" | grep -c "distributionSha512Sum" || echo "Official master branch check"

Repository: KaranSinghG/sql-latency-optimization-demo

Length of output: 365


Update Maven distribution checksum for integrity verification, but note that Maven 3.9.16 requires SHA-512.

The wrapper is missing distributionSha256Sum, disabling integrity checks. However, Apache Maven 3.9.16 only publishes SHA-512 checksums (not SHA-256), so ${distributionUrl}.sha256 does not exist.

Two options to fix this:

  1. Use SHA-512 (preferred): Update wrapper scripts to support distributionSha512Sum and add: distributionSha512Sum=ed41650d42485cfc243fad22158caf9cbb5dc408ce7a09ddb94dd42a019de929ca43065bfa450612cf12bf78b5cafa3884b96c090de326ff590448c933454af3
  2. Use an older Maven version that publishes SHA-256 checksums if SHA-512 support cannot be added.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.mvn/wrapper/maven-wrapper.properties around lines 1 - 3, The
maven-wrapper.properties file is missing a checksum property for integrity
verification. Since Maven 3.9.16 only publishes SHA-512 checksums and not
SHA-256, add the distributionSha512Sum property with the provided checksum value
to the file. Additionally, update the Maven wrapper scripts (typically in the
.mvn/wrapper directory) to support SHA-512 verification instead of SHA-256 to
ensure the integrity check functions properly with the new checksum type.

Comment thread README.md Outdated
Comment on lines +6 to +16
## 📊 Performance Baseline (Unoptimized-Data-small)
- **Data Volume:** 1,000 Customers, 20,000 Orders
- **Endpoint:** `/api/customers/report`
- **Endpoint:** `/api/orders/all`
- **Total DB Queries Executed:** 1,001
- **Average Response Time:**
- **Average Response Time:** 83 ms (10 calls)

## 📊 Performance Baseline (Unoptimized-Data-large)
- **Data Volume:** 10,000 Customers, 2000,000 Orders
- **Endpoint:** `/api/orders/all`
- **Total DB Queries Executed:** 1,001
- **Average Response Time:** 7.06 s (10 calls)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Fix baseline docs to match the implemented API and data notation.

Line 8 and Line 14 list /api/orders/all, but the controller exposes /orders/all. Line 13 also has a numeric typo (2000,000).

Suggested change
-- **Endpoint:** `/api/orders/all`
+- **Endpoint:** `/orders/all`
...
-- **Data Volume:** 10,000 Customers, 2000,000 Orders
+- **Data Volume:** 10,000 Customers, 2,000,000 Orders
-- **Endpoint:** `/api/orders/all`
+- **Endpoint:** `/orders/all`
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
## 📊 Performance Baseline (Unoptimized-Data-small)
- **Data Volume:** 1,000 Customers, 20,000 Orders
- **Endpoint:** `/api/customers/report`
- **Endpoint:** `/api/orders/all`
- **Total DB Queries Executed:** 1,001
- **Average Response Time:**
- **Average Response Time:** 83 ms (10 calls)
## 📊 Performance Baseline (Unoptimized-Data-large)
- **Data Volume:** 10,000 Customers, 2000,000 Orders
- **Endpoint:** `/api/orders/all`
- **Total DB Queries Executed:** 1,001
- **Average Response Time:** 7.06 s (10 calls)
## 📊 Performance Baseline (Unoptimized-Data-small)
- **Data Volume:** 1,000 Customers, 20,000 Orders
- **Endpoint:** `/orders/all`
- **Total DB Queries Executed:** 1,001
- **Average Response Time:** 83 ms (10 calls)
## 📊 Performance Baseline (Unoptimized-Data-large)
- **Data Volume:** 10,000 Customers, 2,000,000 Orders
- **Endpoint:** `/orders/all`
- **Total DB Queries Executed:** 1,001
- **Average Response Time:** 7.06 s (10 calls)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@README.md` around lines 6 - 16, The README.md file contains endpoint and
formatting errors in the Performance Baseline sections. The endpoints listed as
`/api/orders/all` in both the Unoptimized-Data-small and Unoptimized-Data-large
sections should be corrected to `/orders/all` to match the actual controller
implementation. Additionally, the data volume in the Unoptimized-Data-large
section shows an incorrectly formatted number `2000,000` which should be
corrected to `2,000,000` to use proper comma notation for the 2 million orders.

Comment on lines +29 to +35
@GetMapping("/all")
public List<Order> getAllOrders() {
Long t1 = System.currentTimeMillis();
List<Order> orders = orderRepository.findAll();
Long t2 = System.currentTimeMillis();
System.out.println("Time taken by findAll(): " + (t2 - t1) + " ms");
return orders;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Avoid unbounded findAll() in the API path; paginate this endpoint.

Line 32 loads every order into memory. With the documented large dataset, this can degrade availability via long request times and memory spikes.

Suggested change
+import org.springframework.data.domain.PageRequest;
+import org.springframework.web.bind.annotation.RequestParam;
...
     `@GetMapping`("/all")
-    public List<Order> getAllOrders() {
+    public List<Order> getAllOrders(
+            `@RequestParam`(defaultValue = "0") int page,
+            `@RequestParam`(defaultValue = "100") int size) {
         Long t1 = System.currentTimeMillis();
-        List<Order> orders = orderRepository.findAll();
+        List<Order> orders = orderRepository.findAll(PageRequest.of(page, size)).getContent();
         Long t2 = System.currentTimeMillis();
         System.out.println("Time taken by findAll(): " + (t2 - t1) + " ms");
         return orders;
     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@GetMapping("/all")
public List<Order> getAllOrders() {
Long t1 = System.currentTimeMillis();
List<Order> orders = orderRepository.findAll();
Long t2 = System.currentTimeMillis();
System.out.println("Time taken by findAll(): " + (t2 - t1) + " ms");
return orders;
`@GetMapping`("/all")
public List<Order> getAllOrders(
`@RequestParam`(defaultValue = "0") int page,
`@RequestParam`(defaultValue = "100") int size) {
Long t1 = System.currentTimeMillis();
List<Order> orders = orderRepository.findAll(PageRequest.of(page, size)).getContent();
Long t2 = System.currentTimeMillis();
System.out.println("Time taken by findAll(): " + (t2 - t1) + " ms");
return orders;
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/main/java/com/demo/sqlOptimization/controller/OrderController.java`
around lines 29 - 35, The getAllOrders() method in OrderController is loading
all orders into memory using unbounded findAll() which causes performance
degradation with large datasets. Refactor this endpoint to implement pagination
by adding a Pageable parameter to the getAllOrders() method signature, update
the orderRepository.findAll() call to pass the Pageable parameter, and change
the return type from List<Order> to Page<Order> to properly handle paginated
results.

Comment on lines +14 to +30
@Component
public class SeedDataCreator implements CommandLineRunner {

private final CustomerRepository customerRepository;
private final OrderRepository orderRepository;

public SeedDataCreator(CustomerRepository customerRepository, OrderRepository orderRepository) {
this.customerRepository = customerRepository;
this.orderRepository = orderRepository;
}

@Override
@Transactional
public void run(String... args) throws Exception {
if(customerRepository.count()>0) {
return;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify seeding is currently ungated and whether any profile/property gating exists.
rg -n -C2 '`@Component`|`@Profile`|`@ConditionalOnProperty`|implements CommandLineRunner' src/main/java/com/demo/sqlOptimization/SeedDataCreator.java
rg -n -S 'seed|spring.profiles.active|demo' src/main/resources/application.yaml src/test

Repository: KaranSinghG/sql-latency-optimization-demo

Length of output: 387


🏁 Script executed:

cat -n src/main/java/com/demo/sqlOptimization/SeedDataCreator.java

Repository: KaranSinghG/sql-latency-optimization-demo

Length of output: 1773


🏁 Script executed:

find src/test -type f \( -name "*.java" -o -name "*.yaml" -o -name "*.properties" \) | head -20

Repository: KaranSinghG/sql-latency-optimization-demo

Length of output: 161


🏁 Script executed:

rg -n "`@ActiveProfiles`|`@SpringBootTest`|spring.profiles.active" src/test

Repository: KaranSinghG/sql-latency-optimization-demo

Length of output: 179


🏁 Script executed:

cat -n src/test/java/com/demo/sqlOptimization/SqlOptimizationApplicationTests.java

Repository: KaranSinghG/sql-latency-optimization-demo

Length of output: 401


🏁 Script executed:

find src/test -type f \( -name "application*.yaml" -o -name "application*.properties" \)

Repository: KaranSinghG/sql-latency-optimization-demo

Length of output: 67


Add @Profile("demo") annotation to prevent seeding in test environments.

SeedDataCreator is an always-on @Component without profile gating, so it runs on every context startup (including @SpringBootTest) and injects 20,000 demo records. The internal guard on line 28 only prevents re-seeding within the same instance—it does not isolate tests from demo data contamination.

Suggested change
+import org.springframework.context.annotation.Profile;
 import org.springframework.stereotype.Component;
 ...
+@Profile("demo")
 `@Component`
 public class SeedDataCreator implements CommandLineRunner {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@Component
public class SeedDataCreator implements CommandLineRunner {
private final CustomerRepository customerRepository;
private final OrderRepository orderRepository;
public SeedDataCreator(CustomerRepository customerRepository, OrderRepository orderRepository) {
this.customerRepository = customerRepository;
this.orderRepository = orderRepository;
}
@Override
@Transactional
public void run(String... args) throws Exception {
if(customerRepository.count()>0) {
return;
}
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
`@Profile`("demo")
`@Component`
public class SeedDataCreator implements CommandLineRunner {
private final CustomerRepository customerRepository;
private final OrderRepository orderRepository;
public SeedDataCreator(CustomerRepository customerRepository, OrderRepository orderRepository) {
this.customerRepository = customerRepository;
this.orderRepository = orderRepository;
}
`@Override`
`@Transactional`
public void run(String... args) throws Exception {
if(customerRepository.count()>0) {
return;
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/main/java/com/demo/sqlOptimization/SeedDataCreator.java` around lines 14
- 30, The SeedDataCreator class is missing profile gating which causes it to run
in all environments including tests. Add the `@Profile`("demo") annotation to the
SeedDataCreator class definition (above the `@Component` annotation) to ensure the
component is only instantiated when the "demo" profile is active, preventing
seed data injection in test environments while keeping the existing count guard
as a secondary safety measure.

@KaranSinghG
KaranSinghG merged commit 97758f3 into main Jun 20, 2026
1 check passed
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.

1 participant