Skip to content

Commit 1fab05e

Browse files
committed
2 parents 5e811a5 + 796cf4a commit 1fab05e

5 files changed

Lines changed: 21 additions & 3 deletions

File tree

src/main/java/com/back/web7_9_codecrete_be/domain/artists/repository/ArtistRepository.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@
1414
@Repository
1515
public interface ArtistRepository extends JpaRepository<Artist, Long> {
1616

17+
// 아티스트 상세 조회용 - artistGenres와 genre를 fetch join하여 N+1 문제 방지
18+
@Query("""
19+
SELECT DISTINCT a FROM Artist a
20+
LEFT JOIN FETCH a.artistGenres ag
21+
LEFT JOIN FETCH ag.genre
22+
WHERE a.id = :id
23+
""")
24+
java.util.Optional<Artist> findByIdWithArtistGenres(@Param("id") Long id);
25+
1726
@Query("SELECT a FROM Artist a WHERE a.nameKo IS NULL ORDER BY a.id ASC")
1827
List<Artist> findByNameKoIsNullOrderByIdAsc(Pageable pageable);
1928

src/main/java/com/back/web7_9_codecrete_be/domain/artists/service/ArtistService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public Slice<ArtistListResponse> listArtist(Pageable pageable, User user, Artist
100100

101101
@Transactional(readOnly = true)
102102
public ArtistDetailResponse getArtistDetail(Long artistId) {
103-
Artist artist = artistRepository.findById(artistId)
103+
Artist artist = artistRepository.findByIdWithArtistGenres(artistId)
104104
.orElseThrow(() -> new BusinessException(ArtistErrorCode.ARTIST_NOT_FOUND));
105105

106106
if (artist.getSpotifyArtistId() == null) {

src/main/java/com/back/web7_9_codecrete_be/domain/artists/service/spotify/application/SpotifyDetailService.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ public SpotifyArtistDetailCache fetchDetailFromApi(String spotifyArtistId) {
4949
throw e;
5050
} catch (Exception e) {
5151
throw new RuntimeException("Exception during getArtist API call", e);
52+
} finally {
53+
spotifyRateLimiter.release();
5254
}
5355
}, "getArtistDetail getArtist spotifyId=" + spotifyArtistId);
5456

@@ -80,6 +82,8 @@ private Track[] safeGetTopTracks(SpotifyApi api, String artistId) {
8082
throw e;
8183
} catch (Exception e) {
8284
throw new RuntimeException("Exception during getArtistsTopTracks API call", e);
85+
} finally {
86+
spotifyRateLimiter.release();
8387
}
8488
}, "safeGetTopTracks artistId=" + artistId);
8589
} catch (RuntimeException e) {
@@ -103,6 +107,8 @@ private Paging<AlbumSimplified> safeGetAlbums(SpotifyApi api, String artistId) {
103107
throw e;
104108
} catch (Exception e) {
105109
throw new RuntimeException("Exception during getArtistsAlbums API call", e);
110+
} finally {
111+
spotifyRateLimiter.release();
106112
}
107113
}, "safeGetAlbums artistId=" + artistId);
108114
} catch (RuntimeException e) {

src/main/java/com/back/web7_9_codecrete_be/domain/artists/service/spotify/cache/SpotifyCacheService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public SpotifyArtistDetailCache getCached(String spotifyArtistId) {
4141

4242
return objectMapper.convertValue(cached, SpotifyArtistDetailCache.class);
4343
} catch (Exception e) {
44-
log.warn("Redis 캐시 조회 실패: spotifyArtistId={}", spotifyArtistId, e);
44+
log.error("Redis 캐시 조회 실패: spotifyArtistId={}", spotifyArtistId, e);
4545
return null;
4646
}
4747
}

src/main/java/com/back/web7_9_codecrete_be/global/config/RedisConfig.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ public class RedisConfig {
2525
@Bean
2626
public RedisConnectionFactory redisConnectionFactory() {
2727
final RedisStandaloneConfiguration configuration = new RedisStandaloneConfiguration(host,port);
28-
return new LettuceConnectionFactory(configuration);
28+
LettuceConnectionFactory factory = new LettuceConnectionFactory(configuration);
29+
// Redis 연결 타임아웃 설정 (5초)
30+
factory.setTimeout(5000);
31+
return factory;
2932
}
3033

3134
//문자열만 사용할 때(refreshToken)

0 commit comments

Comments
 (0)