feat(repo): 최근 3일 내 이미지 보유 캐릭터 id 일괄 조회 쿼리 추가

- 내용: `findCharacterIdsWithRecentImages(characterIds, since)` 추가
- 본문: 왜(이유) – N+1 제거, 무엇 – IN 기반 벌크 조회
This commit is contained in:
2025-11-13 22:41:20 +09:00
parent 9f6bdf6ed8
commit e4c1cf5a9a

View File

@@ -8,7 +8,9 @@ import org.springframework.data.domain.Page
import org.springframework.data.domain.Pageable
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.Query
import org.springframework.data.repository.query.Param
import org.springframework.stereotype.Repository
import java.time.LocalDateTime
@Repository
interface CharacterImageRepository : JpaRepository<CharacterImage, Long>, CharacterImageQueryRepository {
@@ -26,6 +28,21 @@ interface CharacterImageRepository : JpaRepository<CharacterImage, Long>, Charac
"WHERE ci.chatCharacter.id = :characterId AND ci.isActive = true"
)
fun findMaxSortOrderByCharacterId(characterId: Long): Int
@Query(
"""
select distinct c.id
from CharacterImage ci
join ci.chatCharacter c
where ci.isActive = true
and ci.createdAt >= :since
and c.id in :characterIds
"""
)
fun findCharacterIdsWithRecentImages(
@Param("characterIds") characterIds: List<Long>,
@Param("since") since: LocalDateTime
): List<Long>
}
interface CharacterImageQueryRepository {