Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] rank pagig bug 해결 #494

Merged
merged 2 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public interface RankRepository extends JpaRepository<Rank, Long> {
+ " GROUP BY p.user_id) pg "
+ "ON pg.user_id = u.id "
+ "WHERE r.season_id = :seasonId AND (r.losses > 0 OR r.wins > 0) "
+ "LIMIT :pageSize OFFSET :pageNum ", nativeQuery = true)
List<RankV2Dto> findPppRankBySeasonId(@Param("pageNum")int pageNum, @Param("pageSize")int pageSize, @Param("seasonId") Long seasonId);
+ "LIMIT :limit OFFSET :offset ", nativeQuery = true)
List<RankV2Dto> findPppRankBySeasonId(@Param("offset")int offset, @Param("limit")int limit, @Param("seasonId") Long seasonId);

@Query(value = "SELECT count(*) "
+ "FROM Ranks r "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,13 @@ public ExpRankPageResponseDto getExpRankPage(PageRequest pageRequest, UserDto cu
users.getTotalPages(),
expRankDtos);
}

@Cacheable(value = "expRanking", cacheManager = "gameCacheManager",
key = "#pageRequest.pageNumber + #pageRequest.pageSize")
public List<ExpRankDto> getExpRankList(PageRequest pageRequest) {
Season curSeason = seasonFindService.findCurrentSeason(LocalDateTime.now());
List<ExpRankV2Dto> expRankV2Dtos = userRepository.findExpRank(pageRequest.getPageNumber(), pageRequest.getPageSize(), curSeason.getId());
int pageOffset = pageRequest.getPageNumber() * pageRequest.getPageSize();
List<ExpRankV2Dto> expRankV2Dtos = userRepository.findExpRank(pageOffset, pageRequest.getPageSize(), curSeason.getId());
return expRankV2Dtos.stream().map(ExpRankDto::from).collect(Collectors.toList());
}

Expand Down Expand Up @@ -119,7 +121,8 @@ public RankPageResponseDto getRankPageV2(PageRequest pageRequest, UserDto curUse

int myRank = rankRepository.findRankByUserIdAndSeasonId(curUser.getId(), season.getId())
.orElse(-1);
List<RankDto> rankList = rankRepository.findPppRankBySeasonId(pageRequest.getPageNumber(), pageRequest.getPageSize(), season.getId())
int pageOffset = pageRequest.getPageNumber() * pageRequest.getPageSize();
List<RankDto> rankList = rankRepository.findPppRankBySeasonId(pageOffset, pageRequest.getPageSize(), season.getId())
.stream().map(RankDto::from).collect(Collectors.toList());
return new RankPageResponseDto(myRank, pageRequest.getPageNumber() + 1, totalPage, rankList);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public interface UserRepository extends JpaRepository<User, Long> {
+ "FROM User u LEFT JOIN Ranks r "
+ "ON u.id = r.user_id "
+ "WHERE r.season_id = :seasonId AND u.total_exp > 0 "
+ "LIMIT :pageSize OFFSET :pageNum", nativeQuery = true)
List<ExpRankV2Dto> findExpRank(@Param("pageNum")int pageNum, @Param("pageSize")int pageSize, @Param("seasonId")Long seasonId);
+ "LIMIT :limit OFFSET :offset", nativeQuery = true)
List<ExpRankV2Dto> findExpRank(@Param("offset")int offset, @Param("limit")int limit, @Param("seasonId")Long seasonId);

}
Loading