Skip to content

Commit

Permalink
Merge pull request #145 from teamterning/fix/#140
Browse files Browse the repository at this point in the history
[🔨 fix/#140] 검색화면 totalPages, totalCount 데이터 부정확한 오류 수정 및 count 쿼리 성능 개선
  • Loading branch information
JungYoonShin authored Sep 25, 2024
2 parents f763343 + 65a52da commit bdd8af6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ public enum ProfileImage {
LUCKY("lucky"),
SMART("smart"),
GLASS("glass"),
CALENDAR("calendar");
CALENDAR("calendar"),
PASSION("passion");

private final String value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.core.types.dsl.Expressions;
import com.querydsl.core.types.dsl.NumberTemplate;
import com.querydsl.jpa.impl.JPAQuery;
import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.data.support.PageableExecutionUtils;
import org.terning.terningserver.domain.InternshipAnnouncement;
import org.terning.terningserver.domain.enums.Grade;
import org.terning.terningserver.domain.enums.WorkingPeriod;
Expand Down Expand Up @@ -63,31 +65,25 @@ public Page<InternshipAnnouncement> searchInternshipAnnouncement(String keyword,

List<InternshipAnnouncement> internshipAnnouncements = jpaQueryFactory
.selectFrom(internshipAnnouncement)
.leftJoin(internshipAnnouncement.scraps).fetchJoin()
.leftJoin(internshipAnnouncement.scraps)
.where(contentLike(keyword))
.orderBy(sortAnnouncementsByDeadline().asc(), createOrderSpecifier(sortBy))
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.fetch();

Long count = jpaQueryFactory
JPAQuery<Long> count = jpaQueryFactory
.select(internshipAnnouncement.count())
.from(internshipAnnouncement)
.leftJoin(internshipAnnouncement.scraps)
.where(contentLike(keyword))
.fetchOne();
.where(contentLike(keyword));

// 인턴공고가 없을 경우, 즉 count가 null일 경우 0L을 기본값으로 설정
long announcementCount = (count != null) ? count : 0L;

return new PageImpl<>(internshipAnnouncements, pageable, announcementCount);
return PageableExecutionUtils.getPage(internshipAnnouncements, pageable, count::fetchOne);
}

private BooleanExpression contentLike(String keyword) {
return internshipAnnouncement.title.contains(keyword);
}


//정렬 조건(5가지, 채용 마감 이른 순, 짧은 근무 기간 순, 긴 근무 기간 순,
private OrderSpecifier createOrderSpecifier(String sortBy) {
return switch (sortBy) {
Expand Down

0 comments on commit bdd8af6

Please sign in to comment.