Skip to content

[fix] neon lazy init 적용 - #243

Merged
chan-byeong merged 1 commit into
devfrom
fix/#242/bug-fix
Apr 16, 2026
Merged

[fix] neon lazy init 적용#243
chan-byeong merged 1 commit into
devfrom
fix/#242/bug-fix

Conversation

@chan-byeong

@chan-byeong chan-byeong commented Apr 16, 2026

Copy link
Copy Markdown
Contributor

📌 Summary

해당 PR에 대한 작업 내용을 요약하여 작성해주세요.

관련 있는 Issue를 태그해주세요. (e.g. > - #1)

📄 Tasks

해당 PR에 수행한 작업을 작성해주세요.

👀 To Reviewer

리뷰어에게 요청하는 내용을 작성해주세요.

📸 Screenshot

작업한 내용에 대한 스크린샷을 첨부해주세요.

Summary by CodeRabbit

릴리스 노트

이번 업데이트는 주로 내부 인프라 개선에 중점을 두었습니다.

  • Refactor

    • 데이터베이스 초기화 메커니즘 개선
  • Tests

    • 테스트 환경 설정 최적화
  • Chores

    • 테스트 환경 구성 업데이트

사용자에게 직접적인 기능상 변화는 없습니다.

@chan-byeong chan-byeong self-assigned this Apr 16, 2026
@chan-byeong
chan-byeong requested a review from a team as a code owner April 16, 2026 10:17
@chan-byeong chan-byeong added the 🚨 HOTFIX 긴급 수정 label Apr 16, 2026
@chan-byeong
chan-byeong requested review from haesol2022 and removed request for a team April 16, 2026 10:17
@coderabbitai

coderabbitai Bot commented Apr 16, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

데이터베이스 초기화 방식을 eager에서 lazy로 변경하였습니다. Proxy 패턴을 통해 첫 접근 시점에만 DB 인스턴스를 생성하도록 수정하였고, Vitest 설정에서 환경 변수 주입 방식을 변경하여 별도 setup 파일로 분리하였습니다.

Changes

Cohort / File(s) Summary
데이터베이스 초기화 구조 변경
apps/web/src/shared/db/index.ts
Eager 초기화에서 Lazy 초기화로 변경. 내부 캐시된 _db 인스턴스를 getDb()로만 접근 가능하게 수정하고, 내보낸 db를 Proxy로 변경하여 기존 사용 패턴(db.query, db.insert 등) 유지
테스트 환경 설정 개선
apps/web/vitest.config.mts, apps/web/vitest.setup.ts
Vitest 설정에서 인라인 환경 변수 주입 제거하고 setupFiles 추가. 새로운 setup 파일에서 @/shared/db 모듈을 전역 모의 객체로 대체하여 테스트 환경의 실제 DB 접근 방지

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • blueiz920

Poem

🐰 Lazy 토끼가 DB를 깨물어
Proxy 마법으로 나태함을 누리고
필요할 때만 일어나는 현명함,
테스트 숲에선 가짜 대나무를 먹으며
진짜 뿌리를 지키는 우리의 스마트 버그 수정! 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed PR은 Neon 데이터베이스의 lazy initialization 패턴을 적용하여 최종 발표 전 버그 수정 요구사항을 충족합니다.
Out of Scope Changes check ✅ Passed 모든 변경사항은 lazy initialization 패턴 적용과 테스트 환경 설정에 관련되어 있으며 scope 내에 있습니다.

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


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: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@apps/web/src/shared/db/index.ts`:
- Around line 22-26: The Proxy exported as db only implements the get trap which
causes operations like "'query' in db" and "Object.keys(db)" to behave
incorrectly; update the Proxy created around {} as DB to also implement at least
the has and ownKeys (and corresponding getOwnPropertyDescriptor) traps so
reflective operations consult getDb() results (use getDb() to check property
existence in has, return the target object's keys via ownKeys by reflecting on
the current DB instance, and provide property descriptors in
getOwnPropertyDescriptor). Refer to the db Proxy, getDb(), and DB type when
adding these traps.
🪄 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: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 132e254b-4f61-4473-a205-56aae0db495b

📥 Commits

Reviewing files that changed from the base of the PR and between 60b0049 and 56cbd1b.

📒 Files selected for processing (3)
  • apps/web/src/shared/db/index.ts
  • apps/web/vitest.config.mts
  • apps/web/vitest.setup.ts

Comment on lines +22 to +26
export const db = new Proxy({} as DB, {
get(_, prop) {
return getDb()[prop as keyof DB];
},
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

Proxy에 get 트랩만 구현되어 있어 일부 연산에서 예기치 않은 동작 가능

현재 Proxy는 get 트랩만 구현되어 있습니다. 대부분의 DB 사용 케이스(db.query, db.insert 등)에서는 문제없지만, 다음과 같은 코드가 있으면 의도와 다르게 동작합니다:

  • 'query' in db → 항상 false (빈 객체 기준)
  • Object.keys(db) → 빈 배열 반환

현재 코드베이스에서 이런 패턴이 없다면 문제없지만, 필요시 추가 트랩을 구현할 수 있습니다.

🔧 더 완전한 Proxy 구현 (필요시)
 export const db = new Proxy({} as DB, {
   get(_, prop) {
     return getDb()[prop as keyof DB];
   },
+  has(_, prop) {
+    return prop in getDb();
+  },
+  ownKeys() {
+    return Reflect.ownKeys(getDb());
+  },
+  getOwnPropertyDescriptor(_, prop) {
+    return Object.getOwnPropertyDescriptor(getDb(), prop);
+  },
 });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/web/src/shared/db/index.ts` around lines 22 - 26, The Proxy exported as
db only implements the get trap which causes operations like "'query' in db" and
"Object.keys(db)" to behave incorrectly; update the Proxy created around {} as
DB to also implement at least the has and ownKeys (and corresponding
getOwnPropertyDescriptor) traps so reflective operations consult getDb() results
(use getDb() to check property existence in has, return the target object's keys
via ownKeys by reflecting on the current DB instance, and provide property
descriptors in getOwnPropertyDescriptor). Refer to the db Proxy, getDb(), and DB
type when adding these traps.

@chan-byeong
chan-byeong merged commit b4e7042 into dev Apr 16, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🚨 HOTFIX 긴급 수정

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[fix] 버그 수정

1 participant