Skip to content

feat(lazy-connection): lazyConnectionDataSourceProxy 빈 통해 커넥션 점유기간 최소화#278

Merged
huhdy32 merged 2 commits intodevelopfrom
feat/lazy-connection
Jan 9, 2026
Merged

feat(lazy-connection): lazyConnectionDataSourceProxy 빈 통해 커넥션 점유기간 최소화#278
huhdy32 merged 2 commits intodevelopfrom
feat/lazy-connection

Conversation

@huhdy32
Copy link
Collaborator

@huhdy32 huhdy32 commented Jan 6, 2026

  • 외부 API 요청과 DB 커넥션 점유 분리
  • 전역 적용

Summary by CodeRabbit

  • Infrastructure

    • Added lazy connection initialization to optimize when database connections are created and reduce resource overhead.
    • Introduced a new shared configuration module for centralized data source management and connection pooling.
  • Dependencies

    • Added Spring Data JPA support to the shared module and wired the monolith API to use the new module.

✏️ Tip: You can customize this high-level summary in your review settings.

@huhdy32 huhdy32 self-assigned this Jan 6, 2026
@coderabbitai
Copy link

coderabbitai bot commented Jan 6, 2026

📝 Walkthrough

Walkthrough

Adds a new Gradle module common:mathrank-lazy-connection containing a Spring configuration that exposes a HikariDataSource and a primary LazyConnectionDataSourceProxy; the module is included in settings and added as a dependency to the monolith API module.

Changes

Cohort / File(s) Summary
Gradle Module Registration
settings.gradle
Registered new module 'common:mathrank-lazy-connection' in the multi-project include(...) lists.
Monolith API Integration
app/api/monolith-api/build.gradle
Added dependency: implementation project(':common:mathrank-lazy-connection').
New Module Build
common/mathrank-lazy-connection/build.gradle
Added build file with dependency org.springframework.boot:spring-boot-starter-data-jpa.
Lazy Connection Configuration
common/mathrank-lazy-connection/src/main/java/kr/co/mathrank/common/lazyconnection/LazyConnectionDataSourceProxyConfiguration.java
New package-private Spring @Configuration providing HikariDataSource hikariDataSource(DataSourceProperties) and @Primary DataSource lazyConnectionDataSource(HikariDataSource) (wraps in LazyConnectionDataSourceProxy).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

enhancement

Poem

🐰 I nibble code where Gradle grows,

A proxy snug where Hikari flows.
Lazy springs that sip, not shout—
Connections wake when called about.
Hop, build, and run — a quiet rout.

Pre-merge checks and finishing touches

❌ 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%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: implementing a lazyConnectionDataSourceProxy bean to minimize connection holding time, which aligns with the changeset that adds this new Spring configuration module.
✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cae20e1 and 3e71cbc.

📒 Files selected for processing (1)
  • common/mathrank-lazy-connection/src/main/java/kr/co/mathrank/common/lazyconnection/LazyConnectionDataSourceProxyConfiguration.java
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: test
🔇 Additional comments (3)
common/mathrank-lazy-connection/src/main/java/kr/co/mathrank/common/lazyconnection/LazyConnectionDataSourceProxyConfiguration.java (3)

1-12: Good cleanup on imports!

The unused javax.xml.crypto.Data import has been removed. All current imports are necessary and properly organized.


22-26: Lazy connection proxy setup looks correct.

The LazyConnectionDataSourceProxy wrapping is implemented correctly:

  • Wraps the HikariDataSource to defer physical connection acquisition until first SQL operation
  • @Primary ensures this proxy is the default DataSource bean for injection
  • Returns DataSource interface type for flexibility

This achieves the PR objective of minimizing database connection hold time, particularly beneficial when transactions include external API calls.


15-20: No changes needed. The configuration properly handles Spring Boot's DataSource auto-configuration through the @Primary annotation on the lazyConnectionDataSource bean, ensuring no conflicts occur. Spring Boot auto-configures DataSourceProperties, which is correctly used here to build the HikariDataSource, and the @Primary designator on the wrapper ensures the lazy proxy is selected as the primary DataSource.


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.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @huhdy32, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

이 풀 리퀘스트는 LazyConnectionDataSourceProxy를 구현하여 데이터베이스 연결 관리 방식을 최적화하는 것을 목표로 합니다. 이 전략은 외부 API 호출이 완료된 후와 같이 데이터베이스 연결이 실제로 필요할 때만 연결을 획득하도록 보장하여, 연결이 점유되는 시간을 줄입니다. 이러한 지연 연결 프록시의 전역적인 적용은 리소스 활용도를 개선하고 시스템 성능을 향상시킬 것으로 기대됩니다.

Highlights

  • 지연 연결 데이터 소스 프록시 도입: 데이터베이스 연결 점유 시간을 최소화하기 위해 LazyConnectionDataSourceProxy 빈이 도입되었습니다.
  • 외부 API 요청과 DB 커넥션 분리: 외부 API 요청 처리와 DB 커넥션 점유를 분리하여, DB 연결이 실제로 필요할 때까지 연결 획득을 지연시킵니다.
  • 전역 적용: 이 변경 사항은 시스템 전반에 걸쳐 전역적으로 적용됩니다.
  • 새로운 Gradle 모듈 추가: common:mathrank-lazy-connection이라는 새로운 Gradle 모듈이 추가되어 지연 연결 관련 로직을 캡슐화합니다.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

이 PR은 LazyConnectionDataSourceProxy를 도입하여 DB 커넥션 점유 시간을 최적화하는 좋은 변경입니다. 특히 외부 API 호출과 같이 DB를 사용하지 않는 작업 중에 커넥션 풀의 커넥션을 불필요하게 점유하는 것을 방지할 수 있습니다. 전반적인 접근 방식은 좋지만, 새로 추가된 common:mathrank-lazy-connection 모듈의 재사용성과 명확성을 높이기 위해 몇 가지 개선점을 제안합니다. 주요 내용은 다음과 같습니다:

  • 불필요한 import 문 제거
  • Spring Boot 자동 설정을 활용하여 구성 클래스를 더 견고하게 만드는 방법 제안

자세한 내용은 각 파일의 인라인 코멘트를 확인해주세요.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI Agents
In
@common/mathrank-lazy-connection/src/main/java/kr/co/mathrank/common/lazyconnection/LazyConnectionDataSourceProxyConfiguration.java:
- Line 4: Remove the unused import javax.xml.crypto.Data from the
LazyConnectionDataSourceProxyConfiguration class; open the class
LazyConnectionDataSourceProxyConfiguration and delete the import line (or run
the IDE's organize/imports) so only needed imports remain.
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4869ab3 and cae20e1.

📒 Files selected for processing (4)
  • app/api/monolith-api/build.gradle
  • common/mathrank-lazy-connection/build.gradle
  • common/mathrank-lazy-connection/src/main/java/kr/co/mathrank/common/lazyconnection/LazyConnectionDataSourceProxyConfiguration.java
  • settings.gradle
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: test
🔇 Additional comments (6)
settings.gradle (1)

72-72: LGTM!

The new module is correctly registered in the Gradle build configuration.

common/mathrank-lazy-connection/src/main/java/kr/co/mathrank/common/lazyconnection/LazyConnectionDataSourceProxyConfiguration.java (3)

23-27: Good implementation of lazy connection proxy.

The @Primary annotation correctly ensures this lazy DataSource takes precedence over any auto-configured DataSource beans. The LazyConnectionDataSourceProxy wrapper will defer physical connection acquisition until the connection is actually used, which aligns with the PR objective of minimizing connection hold time.


17-21: DataSourceProperties bean is auto-configured by Spring Boot.

Spring Boot auto-configures the DataSourceProperties bean via the spring-boot-starter-data-jpa dependency included in this module. Since the module declares this dependency, the bean will be available for injection. Consuming applications will also benefit from this transitive dependency, or they can explicitly include spring-boot-starter-data-jpa or spring-boot-starter-jdbc to ensure DataSourceProperties is configured.


15-15: No action needed – configuration class will be properly discovered by Spring Boot.

The package-private visibility of LazyConnectionDataSourceProxyConfiguration is not problematic. Since the main application (DevApiProblemApplication in package kr.co.mathrank) uses @SpringBootApplication, Spring's default component scanning automatically discovers @Configuration classes in that package and all sub-packages, including kr.co.mathrank.common.lazyconnection. Package-private visibility does not prevent Spring's reflection-based bean discovery. No auto-configuration registration files are needed because discovery occurs via component scanning, not auto-configuration.

Likely an incorrect or invalid review comment.

common/mathrank-lazy-connection/build.gradle (1)

1-3: LGTM!

The dependency on spring-boot-starter-data-jpa is appropriate for this module, as it provides the necessary DataSource, JPA, and HikariCP classes used in the configuration.

app/api/monolith-api/build.gradle (1)

44-44: No conflicting DataSource configurations—dependency is safe to add.

The dependency is correctly added to the build.gradle file. Verification confirms there are no other custom DataSource bean definitions in the monolith-api module or app/api/ directory. The @Primary DataSource bean from the lazy-connection module will properly handle precedence without conflicts.

@huhdy32 huhdy32 merged commit 2dac2ce into develop Jan 9, 2026
2 checks passed
@huhdy32 huhdy32 deleted the feat/lazy-connection branch January 9, 2026 07:08
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