diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/live/room/LiveRoomRepository.kt b/src/main/kotlin/kr/co/vividnext/sodalive/live/room/LiveRoomRepository.kt index 35c12cf..9c998c8 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/live/room/LiveRoomRepository.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/live/room/LiveRoomRepository.kt @@ -387,6 +387,15 @@ class LiveRoomQueryRepositoryImpl( 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) + ) + .groupBy(subLiveRoom.member.id) + return queryFactory .select( QGetLatestFinishedLiveQueryResponse( @@ -400,16 +409,8 @@ class LiveRoomQueryRepositoryImpl( .from(liveRoom) .innerJoin(liveRoom.member, member) .where( - liveRoom.updatedAt - .eq( - JPAExpressions.select(subLiveRoom.updatedAt.max()) - .from(subLiveRoom) - .where( - subLiveRoom.member.eq(liveRoom.member) - .and(subLiveRoom.isActive.isFalse) - .and(subLiveRoom.channelName.isNotNull) - ) - ) + Expressions.list(liveRoom.member.id, liveRoom.updatedAt) + .`in`(subQuery) ) .orderBy(liveRoom.updatedAt.desc()) .offset(offset)