Skip to content

Commit fdddf0d

Browse files
committed
[EA3-210] refactor: 최적 시간 투표 mysql 쿼리로 변경
1 parent 506a5f8 commit fdddf0d

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

src/main/java/grep/neogulcoder/domain/timevote/repository/TimeVoteStatRepository.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ public interface TimeVoteStatRepository extends JpaRepository<TimeVoteStat, Long
1515
@Query("UPDATE TimeVoteStat s SET s.activated = false WHERE s.period.studyId = :studyId")
1616
void deactivateAllByPeriod_StudyId(@Param("studyId") Long studyId);
1717

18-
1918
@Modifying
2019
@Query("UPDATE TimeVoteStat s SET s.activated = false WHERE s.period = :period")
2120
void softDeleteByPeriod(@Param("period") TimeVotePeriod period);
@@ -25,12 +24,10 @@ public interface TimeVoteStatRepository extends JpaRepository<TimeVoteStat, Long
2524

2625
@Modifying(clearAutomatically = true)
2726
@Query(value = """
28-
2927
INSERT INTO time_vote_stat (period_id, time_slot, vote_count, activated, created_date, modified_date)
3028
VALUES (:periodId, :timeSlot, :count, true, now(), now())
31-
ON CONFLICT (period_id, time_slot)
32-
DO UPDATE SET
33-
vote_count = time_vote_stat.vote_count + EXCLUDED.vote_count,
29+
ON DUPLICATE KEY UPDATE
30+
vote_count = vote_count + VALUES(vote_count),
3431
modified_date = now(),
3532
activated = true
3633
""", nativeQuery = true)
@@ -44,9 +41,8 @@ void upsertVoteStat(
4441
@Query(value = """
4542
INSERT INTO time_vote_stat (period_id, time_slot, vote_count, activated, created_date, modified_date)
4643
VALUES (:periodId, :timeSlot, :voteCount, true, now(), now())
47-
ON CONFLICT (period_id, time_slot)
48-
DO UPDATE SET
49-
vote_count = EXCLUDED.vote_count,
44+
ON DUPLICATE KEY UPDATE
45+
vote_count = VALUES(vote_count),
5046
modified_date = now(),
5147
activated = true
5248
""", nativeQuery = true)

0 commit comments

Comments
 (0)