fix: 라이브 메인 API - 최근 종료된 라이브
- 쿼리 최적화
This commit is contained in:
		| @@ -4,7 +4,6 @@ import com.querydsl.core.types.Projections | ||||
| import com.querydsl.core.types.dsl.CaseBuilder | ||||
| import com.querydsl.core.types.dsl.Expressions | ||||
| import com.querydsl.core.types.dsl.NumberExpression | ||||
| import com.querydsl.jpa.JPAExpressions | ||||
| import com.querydsl.jpa.impl.JPAQueryFactory | ||||
| import kr.co.vividnext.sodalive.can.use.CanUsage | ||||
| import kr.co.vividnext.sodalive.can.use.QUseCan.useCan | ||||
| @@ -385,40 +384,26 @@ class LiveRoomQueryRepositoryImpl( | ||||
|     } | ||||
|  | ||||
|     override fun getLatestFinishedLive(): List<GetLatestFinishedLiveQueryResponse> { | ||||
|         val liveRoom = liveRoom | ||||
|         val subLiveRoom = QLiveRoom.liveRoom | ||||
|  | ||||
|         val subQuery = JPAExpressions | ||||
|             .select(subLiveRoom.member.id, subLiveRoom.updatedAt.max()) | ||||
|             .from(subLiveRoom) | ||||
|             .where( | ||||
|                 subLiveRoom.isActive.isFalse | ||||
|                     .and(subLiveRoom.channelName.isNotNull) | ||||
|                     .and(subLiveRoom.member.role.eq(MemberRole.CREATOR)) | ||||
|                     .and(subLiveRoom.member.isActive.isTrue) | ||||
|                     .and(subLiveRoom.updatedAt.goe(LocalDateTime.now().minusWeeks(1))) | ||||
|             ) | ||||
|             .groupBy(subLiveRoom.member.id) | ||||
|  | ||||
|         return queryFactory | ||||
|             .select( | ||||
|                 QGetLatestFinishedLiveQueryResponse( | ||||
|                     member.id, | ||||
|                     member.nickname, | ||||
|                     member.profileImage.prepend("/").prepend(cloudFrontHost), | ||||
|                     liveRoom.updatedAt | ||||
|                     liveRoom.updatedAt.max() | ||||
|                 ) | ||||
|             ) | ||||
|             .from(liveRoom) | ||||
|             .innerJoin(liveRoom.member, member) | ||||
|             .where( | ||||
|                 liveRoom.updatedAt.goe(LocalDateTime.now().minusWeeks(1)) | ||||
|                     .and( | ||||
|                         Expressions.list(liveRoom.member.id, liveRoom.updatedAt) | ||||
|                             .`in`(subQuery) | ||||
|                 liveRoom.isActive.isFalse | ||||
|                     .and(liveRoom.channelName.isNotNull) | ||||
|                     .and(liveRoom.updatedAt.goe(LocalDateTime.now().minusWeeks(1))) | ||||
|                     .and(member.isActive.isTrue) | ||||
|                     .and(member.role.eq(MemberRole.CREATOR)) | ||||
|             ) | ||||
|             ) | ||||
|             .orderBy(liveRoom.updatedAt.desc()) | ||||
|             .groupBy(member.id) | ||||
|             .orderBy(liveRoom.updatedAt.max().desc()) | ||||
|             .limit(20) | ||||
|             .fetch() | ||||
|     } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user