From edef83d12b18c7b7a92d1dd06e0276a80807e7f7 Mon Sep 17 00:00:00 2001 From: AYoungSn Date: Wed, 24 Jan 2024 20:02:55 +0900 Subject: [PATCH] [TEST] #232 foreach -> fori --- .../admin/game/service/GameAdminService.java | 16 +++++++--------- .../admin/team/data/TeamUserAdminRepository.java | 2 +- .../com/gg/server/domain/game/data/Game.java | 3 +++ .../com/gg/server/domain/rank/data/Rank.java | 3 +++ .../domain/rank/redis/RankRedisService.java | 4 ++-- .../com/gg/server/domain/team/data/Team.java | 4 ++++ .../com/gg/server/domain/user/data/User.java | 3 +++ 7 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/gg/server/admin/game/service/GameAdminService.java b/src/main/java/com/gg/server/admin/game/service/GameAdminService.java index 12464987f..bdcbff077 100644 --- a/src/main/java/com/gg/server/admin/game/service/GameAdminService.java +++ b/src/main/java/com/gg/server/admin/game/service/GameAdminService.java @@ -134,21 +134,19 @@ public void rankResultEdit(RankGamePPPModifyReqDto reqDto, Long gameId) { throw new NotRecentlyGameException(); } // pchange 가져와서 rank ppp 이전 값을 가지고 새 점수를 바탕으로 다시 계산 - for (TeamUser teamUser : - teamUsers) { - List pChanges = pChangeAdminRepository.findByTeamUser(teamUser.getUser().getId()); + for (int i = 0; i < teamUsers.size(); i++) { + List pChanges = pChangeAdminRepository.findByTeamUser(teamUsers.get(i).getUser().getId()); if (!pChanges.get(0).getGame().getId().equals(gameId)) { throw new PChangeNotExistException(); } - rollbackGameResult(season, teamUser, pChanges); + rollbackGameResult(season, teamUsers.get(i), pChanges); pChangeAdminRepository.deleteById(pChanges.get(0).getId()); + entityManager.flush(); } - for (TeamUser teamUser : - teamUsers) { - updateScore(reqDto, teamUser); + for (int i = 0; i < teamUsers.size(); i++) { + updateScore(reqDto, teamUsers.get(i)); } - entityManager.flush(); - entityManager.clear(); + teamUserAdminRepository.flush(); rankRedisService.updateRankRedis(teamUsers.get(0), teamUsers.get(1), game); tierService.updateAllTier(game.getSeason()); } diff --git a/src/main/java/com/gg/server/admin/team/data/TeamUserAdminRepository.java b/src/main/java/com/gg/server/admin/team/data/TeamUserAdminRepository.java index afbdbaf9f..0fe3650fa 100644 --- a/src/main/java/com/gg/server/admin/team/data/TeamUserAdminRepository.java +++ b/src/main/java/com/gg/server/admin/team/data/TeamUserAdminRepository.java @@ -12,6 +12,6 @@ public interface TeamUserAdminRepository extends JpaRepository { @Query("SELECT tu.user FROM TeamUser tu WHERE tu.team.id = :teamId") List findUsersByTeamId(@Param("teamId") Long teamId); - @Query("SELECT tu FROM TeamUser tu JOIN FETCH tu.team t JOIN FETCH tu.user WHERE tu.team.id IN (:teamId) AND t.id = tu.team.id") + @Query("SELECT tu FROM TeamUser tu JOIN FETCH tu.team t JOIN FETCH tu.user WHERE tu.team.id IN (:teamId)") List findUsersByTeamIdIn(@Param("teamId") List teamId); } diff --git a/src/main/java/com/gg/server/domain/game/data/Game.java b/src/main/java/com/gg/server/domain/game/data/Game.java index c8ab0972a..cab8f8643 100644 --- a/src/main/java/com/gg/server/domain/game/data/Game.java +++ b/src/main/java/com/gg/server/domain/game/data/Game.java @@ -16,10 +16,13 @@ import java.util.List; import java.util.Optional; +import org.hibernate.annotations.DynamicUpdate; + @NoArgsConstructor @AllArgsConstructor @Getter @Entity +@DynamicUpdate public class Game { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/src/main/java/com/gg/server/domain/rank/data/Rank.java b/src/main/java/com/gg/server/domain/rank/data/Rank.java index 275f21646..35c69fff2 100644 --- a/src/main/java/com/gg/server/domain/rank/data/Rank.java +++ b/src/main/java/com/gg/server/domain/rank/data/Rank.java @@ -14,12 +14,15 @@ import javax.validation.constraints.NotNull; import java.io.Serializable; +import org.hibernate.annotations.DynamicUpdate; + @Entity @Getter @Builder @NoArgsConstructor @AllArgsConstructor @Table(name="ranks") +@DynamicUpdate public class Rank extends BaseTimeEntity implements Serializable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/src/main/java/com/gg/server/domain/rank/redis/RankRedisService.java b/src/main/java/com/gg/server/domain/rank/redis/RankRedisService.java index a781959e9..76d053bb7 100644 --- a/src/main/java/com/gg/server/domain/rank/redis/RankRedisService.java +++ b/src/main/java/com/gg/server/domain/rank/redis/RankRedisService.java @@ -75,7 +75,7 @@ public void updatePPP(TeamUser teamuser, RankRedis myTeam, int enemyScore, Integ + "), redis(" + myTeam.getWins() + "), losses: db(" + rank.getLosses() + "), redis(" + myTeam.getLosses() + ")"); rank.modifyUserRank(rank.getPpp() + changedPpp, win, losses); - rankRepository.updateByUserIdAndSeasonId(rank.getUser().getId(), seasonId, rank.getPpp(), win, losses); + // rankRepository.updateByUserIdAndSeasonId(rank.getUser().getId(), seasonId, rank.getPpp(), win, losses); myTeam.updateRank(changedPpp, win, losses); log.info("update after: intraId: " + teamuser.getUser().getIntraId() + ", win: db(" + rank.getWins() @@ -148,7 +148,7 @@ public void rollbackRank(TeamUser teamUser, int ppp, Long seasonId) { rank.modifyUserRank(ppp, win, losses); myTeam.changedRank(ppp, win, losses); updateRankUser(hashkey, RedisKeyManager.getZSetKey(seasonId), teamUser.getUser().getId(), myTeam); - rankRepository.updateByUserIdAndSeasonId(rank.getUser().getId(), seasonId, ppp, win, losses); + // rankRepository.updateByUserIdAndSeasonId(rank.getUser().getId(), seasonId, ppp, win, losses); log.info("After: userId: " + teamUser.getUser().getIntraId() + ", " + "ppp: rank(" + rank.getPpp() + "), redis(" + myTeam.getPpp() + "), win: " + myTeam.getWins() + ", losses: " + myTeam.getLosses()); diff --git a/src/main/java/com/gg/server/domain/team/data/Team.java b/src/main/java/com/gg/server/domain/team/data/Team.java index a3f4e0b5d..dfb2ce647 100644 --- a/src/main/java/com/gg/server/domain/team/data/Team.java +++ b/src/main/java/com/gg/server/domain/team/data/Team.java @@ -16,6 +16,9 @@ import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.validation.constraints.NotNull; + +import org.hibernate.annotations.DynamicUpdate; + import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; @@ -24,6 +27,7 @@ @AllArgsConstructor @Entity @Getter +@DynamicUpdate public class Team { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/src/main/java/com/gg/server/domain/user/data/User.java b/src/main/java/com/gg/server/domain/user/data/User.java index 1a9b58b21..fc4a3e4d4 100644 --- a/src/main/java/com/gg/server/domain/user/data/User.java +++ b/src/main/java/com/gg/server/domain/user/data/User.java @@ -10,9 +10,12 @@ import javax.validation.constraints.NotNull; import java.io.Serializable; +import org.hibernate.annotations.DynamicUpdate; + @Entity @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) +@DynamicUpdate public class User extends BaseTimeEntity implements Serializable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY)