[fix] neon lazy init 적용 - #243
Conversation
📝 WalkthroughWalkthrough데이터베이스 초기화 방식을 eager에서 lazy로 변경하였습니다. Proxy 패턴을 통해 첫 접근 시점에만 DB 인스턴스를 생성하도록 수정하였고, Vitest 설정에서 환경 변수 주입 방식을 변경하여 별도 setup 파일로 분리하였습니다. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ 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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (3)
apps/web/src/shared/db/index.tsapps/web/vitest.config.mtsapps/web/vitest.setup.ts
| export const db = new Proxy({} as DB, { | ||
| get(_, prop) { | ||
| return getDb()[prop as keyof DB]; | ||
| }, | ||
| }); |
There was a problem hiding this comment.
🧹 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.
📌 Summary
해당 PR에 대한 작업 내용을 요약하여 작성해주세요.
📄 Tasks
해당 PR에 수행한 작업을 작성해주세요.
👀 To Reviewer
리뷰어에게 요청하는 내용을 작성해주세요.
📸 Screenshot
작업한 내용에 대한 스크린샷을 첨부해주세요.
Summary by CodeRabbit
릴리스 노트
이번 업데이트는 주로 내부 인프라 개선에 중점을 두었습니다.
Refactor
Tests
Chores
사용자에게 직접적인 기능상 변화는 없습니다.