Skip to content

Commit

Permalink
fix: 최근 게시글 불러오는 sql에서 모든 포스팅 가져오는 문제 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
gusah009 committed Oct 14, 2023
1 parent aff9cd4 commit 98324af
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public class PostService {
private static final int EXAM_ACCESSIBLE_POINT = 30000;
private static final int EXAM_READ_DEDUCTION_POINT = 10000;
private static final String EXAM_READ_POINT_MESSAGE = "족보 열람";
private static final int RECENT_POSTING_COUNT = 10;

@Transactional
public Long create(Post post, Long categoryId, MultipartFile thumbnail, List<MultipartFile> multipartFiles) {
Expand Down Expand Up @@ -361,9 +362,10 @@ private MainPostResponse getMainPostResponse(Post post) {
}

public List<MainPostResponse> getRecentPosts() {
return postRepository.findAllRecent().stream()
return postRepository.findAllRecent(PageRequest.of(0, RECENT_POSTING_COUNT))
.stream()
.map(this::getMainPostResponse)
.limit(10)
.limit(RECENT_POSTING_COUNT)
.toList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public interface PostRepository extends JpaRepository<Post, Long> {
+ "WHERE p.isTemp = false "
+ "AND p.id <> 1 " // virtual post
+ "ORDER BY p.registerTime DESC")
List<Post> findAllRecent();
List<Post> findAllRecent(Pageable pageable);

/**
* 카테고리 + 공지글 제외 + 임시글 제외 + 등록시간 최신순 정렬
Expand Down

0 comments on commit 98324af

Please sign in to comment.