Skip to content

fix: Fine Reminder 3일 간격 로직 수정 (P1 #10)#27

Merged
choihooo merged 2 commits intodevfrom
feat/fine-reminder-3days-fix
Mar 10, 2026
Merged

fix: Fine Reminder 3일 간격 로직 수정 (P1 #10)#27
choihooo merged 2 commits intodevfrom
feat/fine-reminder-3days-fix

Conversation

@choihooo
Copy link
Copy Markdown
Collaborator

🎯 Summary

이 PR의 목적을 한 줄로 요약해주세요
Fine Reminder가 정확히 3일 간격으로 발송되도록 수정 (매일 중복 발송 버그 해결)


🔴 AS-IS

기존 상태 또는 문제점

  • 매일 10:00에 크론이 실행됨
  • daysSinceCreation % 3 === 0 로직으로 3일 간격 체크
  • 문제: 3일째 10:00부터 4일째 10:00까지도 daysSinceCreation = 3으로 계산되어 매일 리마인드 발송

🟢 TO-BE

변경 후 상태 또는 개선점

  • fines 테이블에 lastReminderAt 컬럼 추가
  • 리마인드 발송 후 lastReminderAt 타임스탬프 업데이트
  • 개선: 마지막 리마인드로부터 정확히 3일 경과 시에만 재발송 (3일, 6일, 9일...)

💬 참고사항

리뷰어가 알아야 할 내용, 논의 포인트, 주의사항 등

DB 스키마 변경

-- fines 테이블에 컬럼 추가
ALTER TABLE fines ADD COLUMN last_reminder_at TIMESTAMPTZ;
CREATE INDEX idx_fines_last_reminder_at ON fines(last_reminder_at);

필터 로직

// 이전: daysSinceCreation % 3 === 0
// 신규: 마지막 리마인드로부터 3일 이상 경과 확인

const threeDaysSinceLastReminder = new Date(
  lastReminderAt.getTime() + 3 * 24 * 60 * 60 * 1000
);
return now >= threeDaysSinceLastReminder;

마이그레이션

cd packages/shared
export $(grep DATABASE_URL ../../.env.local | head -1 | xargs)
npx drizzle-kit push --force

P1 #10 문제 해결:
- 문제: 매일 10:00에 실행되므로 daysSinceCreation % 3 === 0 로직이 불안정
- 3일째 10:00에 3일 경과 (3 % 3 = 0) → 리마인드 발송
- 4일째 10:00에도 여전히 리마인드 발송 가능

해결 방법:
1. fines 테이블에 lastReminderAt 컬럼 추가
2. 리마인드 발송 후 lastReminderAt 업데이트
3. 마지막 리마인드로부터 정확히 3일 경과 시만 재발송

변경 사항:
- schema.ts: fines 테이블에 lastReminderAt 컬럼 및 인덱스 추가
- fine-reminder.ts: 필터 로직을 lastReminderAt 기반으로 변경
- fine.service.ts: updateLastReminderAt() 메서드 추가

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@choihooo choihooo requested a review from bbbang105 as a code owner March 10, 2026 08:24
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 10, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
study-admin-web Ready Ready Preview, Comment Mar 10, 2026 8:28am

Priority 1 문제 해결:
1. 필터 로직 버그 수정
   - 이전: createdAt < threeDaysAgo (3일 이전 체크 - 로직 반대)
   - 수정: now < threeDaysSinceCreation (3일 미경과 제외)

2. NULL 처리 로직 개선
   - 이전: !lastReminderAt → 무조건 true (3일 미경과해도 발송)
   - 수정: !lastReminderAt → 3일 경과 확인 후 return true

변경 사항:
- threeDaysAgo 변수 제거
- threeDaysSinceCreation 변수 추가 (createdAt + 3일)
- 주석 명확화

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@choihooo choihooo merged commit 08623e9 into dev Mar 10, 2026
7 checks passed
@choihooo choihooo deleted the feat/fine-reminder-3days-fix branch March 10, 2026 08:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🚨 fix 버그 수정 / 에러 해결

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants