<aside> 💡
모든 회원에게 알림을 보내야하는 상황입니다(브로드캐스트).
회원 50,000명이 DB에 저장되어 있고, 해당 모든 알림 정보를 DB에 저장해야 합니다.
</aside>
PSQLException
Cause: org.postgresql.util.PSQLException: PreparedStatement can have at most 65,535 parameters. Please consider using arrays, or splitting the query in several ones, or using COPY. Given query has 300,060 parameters<EOL>; PreparedStatement can have at most 65,535 parameters. Please consider using arrays, or splitting the query in several ones, or using COPY. Given query has 300,060 parameters]
DB 변경
(PostgreSQL → MySql(MariaDB))DB 테이블 추가
(공지사항 테이블)배치
삽입:
COPY
삽입
@Transactional
public void saveAll(
List<MemberResponseDto> memberList,
Long templateId,
String subject,
String content,
Instant createdAt
) {
if (memberList == null || memberList.isEmpty()) return;
final int CHUNK = 5_000;
for (int i = 0; i < memberList.size(); i += CHUNK) {
int end = Math.min(i + CHUNK, memberList.size());
List<MemberResponseDto> sub = memberList.subList(i, end);
notificationMapper.saveAll(sub, templateId, subject, content, createdAt, StatusIds.Notification.UNREAD);
}
}