From f8e150e73adebcd0836b31d5b43875b6fc73503f Mon Sep 17 00:00:00 2001 From: belljun3395 <195850@jnu.ac.kr> Date: Thu, 8 Aug 2024 12:02:12 +0900 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20in=20=EC=9E=98=EB=AA=BB=EB=90=9C=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=EC=9C=BC=EB=A1=9C=20=EC=9D=B8=ED=95=9C=20?= =?UTF-8?q?=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../writer/WorkBookSubscriberWriter.kt | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/batch/src/main/kotlin/com/few/batch/service/article/writer/WorkBookSubscriberWriter.kt b/batch/src/main/kotlin/com/few/batch/service/article/writer/WorkBookSubscriberWriter.kt index ae6346dd3..17037f66a 100644 --- a/batch/src/main/kotlin/com/few/batch/service/article/writer/WorkBookSubscriberWriter.kt +++ b/batch/src/main/kotlin/com/few/batch/service/article/writer/WorkBookSubscriberWriter.kt @@ -11,6 +11,7 @@ import com.few.email.service.article.dto.Content import com.few.email.service.article.dto.SendArticleEmailArgs import jooq.jooq_dsl.tables.* import org.jooq.DSLContext +import org.jooq.UpdateConditionStep import org.jooq.impl.DSL import org.springframework.stereotype.Component import org.springframework.transaction.annotation.Transactional @@ -170,11 +171,11 @@ class WorkBookSubscriberWriter( try { sendArticleEmailService.send(it.second) } catch (e: Exception) { - memberSuccessRecords[it.first] = false - failRecords["EmailSendFail"] = failRecords.getOrDefault("EmailSendFail", arrayListOf()).apply { - val message = e.message ?: "Unknown Error" - add(mapOf(it.first to message)) - } +// memberSuccessRecords[it.first] = false +// failRecords["EmailSendFail"] = failRecords.getOrDefault("EmailSendFail", arrayListOf()).apply { +// val message = e.message ?: "Unknown Error" +// add(mapOf(it.first to message)) +// } } } @@ -201,13 +202,19 @@ class WorkBookSubscriberWriter( memberSuccessRecords[it.memberId] == true } - val successMemberIds = memberSuccessRecords.filter { it.value }.keys /** 이메일 전송에 성공한 구독자들의 진행률을 업데이트한다.*/ - dslContext.update(subscriptionT) - .set(subscriptionT.PROGRESS, subscriptionT.PROGRESS.add(1)) - .where(subscriptionT.MEMBER_ID.`in`(successMemberIds)) - .and(subscriptionT.TARGET_WORKBOOK_ID.`in`(targetWorkBookIds)) - .execute() + val successMemberIds = memberSuccessRecords.filter { it.value }.keys + val updateTargetMemberRecords = items.filter { it.memberId in successMemberIds } + val updateQueries = mutableListOf>() + for (updateTargetMemberRecord in updateTargetMemberRecords) { + updateQueries.add( + dslContext.update(subscriptionT) + .set(subscriptionT.PROGRESS, updateTargetMemberRecord.progress + 1) + .where(subscriptionT.MEMBER_ID.eq(updateTargetMemberRecord.memberId)) + .and(subscriptionT.TARGET_WORKBOOK_ID.eq(updateTargetMemberRecord.targetWorkBookId)) + ) + } + dslContext.batch(updateQueries).execute() /** 마지막 학습지를 받은 구독자들은 구독을 해지한다.*/ // todo refactoring to batch update From dfce6ab9382ce5d61e862001033fe3e53c2bc655 Mon Sep 17 00:00:00 2001 From: belljun3395 <195850@jnu.ac.kr> Date: Thu, 8 Aug 2024 12:29:28 +0900 Subject: [PATCH 2/3] =?UTF-8?q?chore:=20=EC=A3=BC=EC=84=9D=20=EC=9E=98?= =?UTF-8?q?=EB=AA=BB=20=EC=B6=94=EA=B0=80=EB=90=9C=20=EA=B2=83=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/article/writer/WorkBookSubscriberWriter.kt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/batch/src/main/kotlin/com/few/batch/service/article/writer/WorkBookSubscriberWriter.kt b/batch/src/main/kotlin/com/few/batch/service/article/writer/WorkBookSubscriberWriter.kt index 17037f66a..89f582ae7 100644 --- a/batch/src/main/kotlin/com/few/batch/service/article/writer/WorkBookSubscriberWriter.kt +++ b/batch/src/main/kotlin/com/few/batch/service/article/writer/WorkBookSubscriberWriter.kt @@ -171,11 +171,11 @@ class WorkBookSubscriberWriter( try { sendArticleEmailService.send(it.second) } catch (e: Exception) { -// memberSuccessRecords[it.first] = false -// failRecords["EmailSendFail"] = failRecords.getOrDefault("EmailSendFail", arrayListOf()).apply { -// val message = e.message ?: "Unknown Error" -// add(mapOf(it.first to message)) -// } + memberSuccessRecords[it.first] = false + failRecords["EmailSendFail"] = failRecords.getOrDefault("EmailSendFail", arrayListOf()).apply { + val message = e.message ?: "Unknown Error" + add(mapOf(it.first to message)) + } } } From 672e7d615b6a2eb08bf117ff69561f81cd0e4682 Mon Sep 17 00:00:00 2001 From: belljun3395 <195850@jnu.ac.kr> Date: Thu, 8 Aug 2024 12:31:31 +0900 Subject: [PATCH 3/3] =?UTF-8?q?refactor:=20=EB=A7=88=EC=A7=80=EB=A7=89=20?= =?UTF-8?q?=ED=95=99=EC=8A=B5=EC=A7=80=EB=A5=BC=20=EB=B0=9B=EC=9D=80=20?= =?UTF-8?q?=EA=B5=AC=EB=8F=85=EC=9E=90=EB=8F=84=20batch=EB=A1=9C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../article/writer/WorkBookSubscriberWriter.kt | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/batch/src/main/kotlin/com/few/batch/service/article/writer/WorkBookSubscriberWriter.kt b/batch/src/main/kotlin/com/few/batch/service/article/writer/WorkBookSubscriberWriter.kt index 89f582ae7..e88ac80c1 100644 --- a/batch/src/main/kotlin/com/few/batch/service/article/writer/WorkBookSubscriberWriter.kt +++ b/batch/src/main/kotlin/com/few/batch/service/article/writer/WorkBookSubscriberWriter.kt @@ -217,15 +217,17 @@ class WorkBookSubscriberWriter( dslContext.batch(updateQueries).execute() /** 마지막 학습지를 받은 구독자들은 구독을 해지한다.*/ - // todo refactoring to batch update + val receiveLastDayQueries = mutableListOf>() for (receiveLastDayMember in receiveLastDayMembers) { - dslContext.update(subscriptionT) - .set(subscriptionT.DELETED_AT, LocalDateTime.now()) - .set(subscriptionT.UNSUBS_OPINION, "receive.all") - .where(subscriptionT.MEMBER_ID.eq(receiveLastDayMember.memberId)) - .and(subscriptionT.TARGET_WORKBOOK_ID.eq(receiveLastDayMember.targetWorkBookId)) - .execute() + receiveLastDayQueries.add( + dslContext.update(subscriptionT) + .set(subscriptionT.DELETED_AT, LocalDateTime.now()) + .set(subscriptionT.UNSUBS_OPINION, "receive.all") + .where(subscriptionT.MEMBER_ID.eq(receiveLastDayMember.memberId)) + .and(subscriptionT.TARGET_WORKBOOK_ID.eq(receiveLastDayMember.targetWorkBookId)) + ) } + dslContext.batch(receiveLastDayQueries).execute() return if (failRecords.isNotEmpty()) { mapOf("records" to memberSuccessRecords, "fail" to failRecords)