Skip to content

Conversation

@sweatbuckets
Copy link
Contributor

@sweatbuckets sweatbuckets commented Dec 30, 2025

  1. #⃣ 연관된 이슈
    • 관련 이슈를 명시해주세요.
    • 예: #이슈번호#이슈번호
  2. 📝 작업 내용
    • 이번 PR에서 작업한 내용을 간략히 설명해주세요.
    • 필요한 경우 이미지 첨부 가능.
  3. 📸 스크린샷 (선택)
    • 작업 내용을 시각적으로 표현할 스크린샷을 포함하세요.
  4. 💬 리뷰 요구사항 (선택)
    • 리뷰어가 특히 검토해주었으면 하는 부분이 있다면 작성해주세요.
    • 예: "메서드 XXX의 이름을 더 명확히 하고 싶은데, 좋은 아이디어가 있으신가요?"

Summary by CodeRabbit

  • Performance Improvements

    • Optimized photo album loading by improving image retrieval efficiency, providing faster album browsing and enhanced responsiveness.
  • Documentation

    • Updated field documentation for image content types.

✏️ Tip: You can customize this high-level summary in your review settings.

정윤호 added 2 commits December 30, 2025 00:04
# Conflicts:
#	src/main/java/cc/backend/photoAlbum/service/PhotoAlbumServiceImpl.java
@coderabbitai
Copy link

coderabbitai bot commented Dec 30, 2025

📝 Walkthrough

Walkthrough

The PR updates a documentation comment in the Image entity and introduces batched image retrieval optimization in PhotoAlbumServiceImpl's getPhotoAlbumList method, replacing individual per-album image lookups with a single bulk fetch operation followed by DTO conversion.

Changes

Cohort / File(s) Summary
Documentation Update
src/main/java/cc/backend/image/entity/Image.java
Updated imageUrl field Javadoc comment: changed "actor 이미지 전용" to "casting 이미지 전용"
Batched Image Retrieval
src/main/java/cc/backend/photoAlbum/service/PhotoAlbumServiceImpl.java
Refactored getPhotoAlbumList to batch-fetch album images: extract albumIds from current page, fetch all images at once via findFirstByContentIds with merge strategy, convert to ImageResultWithPresignedUrlDTO map, then assemble DTOs using pre-fetched data instead of per-album lookups

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Service as PhotoAlbumService
    participant DB as Database
    participant ImageService
    participant DTO as DTO Assembly

    Client->>Service: getPhotoAlbumList(pageable)
    
    rect rgb(200, 220, 250)
    Note over Service: Fetch Albums (Single Page)
    Service->>DB: findAll(pageable)
    DB-->>Service: List<Album>
    end
    
    rect rgb(220, 250, 200)
    Note over Service: Batch Image Retrieval (New Optimization)
    Service->>Service: Extract albumIds from page
    Service->>DB: findFirstByContentIds(albumIds)
    DB-->>Service: List<Image>
    Service->>Service: Build albumImageMap (merge first)
    end
    
    rect rgb(250, 230, 200)
    Note over Service: Bulk DTO Conversion
    Service->>ImageService: Convert all images to ImageResultWithPresignedUrlDTO
    ImageService-->>Service: imageDtoMap
    end
    
    rect rgb(240, 240, 240)
    Note over DTO: Assemble Response
    Service->>DTO: Build SinglePhotoAlbumDTO list
    DTO->>DTO: imageDtoMap.get(albumId) per album
    DTO-->>Service: List<SinglePhotoAlbumDTO>
    end
    
    Service-->>Client: Page<SinglePhotoAlbumDTO>
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • PR #121: Modifies PhotoAlbumServiceImpl pagination and bulk image lookup patterns alongside the batched retrieval changes
  • PR #124: Introduces batched/first-image map approach for album image fetching in PhotoAlbumServiceImpl
  • PR #123: Updates PhotoAlbumServiceImpl to batch-fetch images and convert to presigned-URL DTOs

Poem

🐰 Hops of joy for batching bright,
One fetch beats many—what delight!
From solo queries to bulk as one,
The photo albums now load with fun! 🎞️

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description contains only the template placeholder text with no actual content filled in; all required sections remain as instructional examples. Fill in the PR description by: (1) referencing related issue numbers, (2) explaining the batched image retrieval optimization in PhotoAlbumServiceImpl, and (3) optionally adding review requests or screenshots.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The PR title accurately reflects the main change: performance optimization of presigned URL issuance logic through batched image retrieval.
✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d80a12c and 9731ee2.

📒 Files selected for processing (2)
  • src/main/java/cc/backend/image/entity/Image.java
  • src/main/java/cc/backend/photoAlbum/service/PhotoAlbumServiceImpl.java
🔇 Additional comments (5)
src/main/java/cc/backend/image/entity/Image.java (1)

35-35: LGTM! Documentation clarification.

The terminology update from "actor" to "casting" improves clarity in the theater/performance domain context.

src/main/java/cc/backend/photoAlbum/service/PhotoAlbumServiceImpl.java (4)

135-138: LGTM! Clean preparation for batch query.

Extracting album IDs upfront is the correct approach for the N+1 prevention strategy implemented below.


151-163: LGTM! Efficient bulk DTO conversion with presigned URLs.

The empty map guard and batch conversion of images to DTOs with presigned URLs is well-implemented. This centralizes the presigned URL generation instead of calling it per-album.


166-178: LGTM! Clean DTO assembly using pre-fetched data.

The mapping correctly uses the pre-fetched imageDtoMap. Note that imageDtoMap.get(album.getId()) will return null for albums without images, which is passed to imageResultWithPresignedUrlDTO. This appears intentional based on the DTO structure.


140-148: Batch optimization is sound; merge function is defensive but unnecessary.

The query findFirstByContentIds uses a subquery i.id = (SELECT MIN(i2.id) FROM Image i2 WHERE i2.contentId = i.contentId) to guarantee exactly one Image per contentId. The merge function (a, b) -> a is therefore redundant and can be removed in favor of the more standard pattern used elsewhere (e.g., line 362), which collects directly to a Map<Long, Image> without mapping.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/main/java/cc/backend/photoAlbum/service/PhotoAlbumServiceImpl.java (1)

366-373: Apply the same batching optimization here.

The loop calls imageService.getImages() individually for each image, creating an N+1 query pattern. This is inconsistent with the optimization just implemented in getPhotoAlbumList (lines 151-163), where presigned URLs are generated in bulk.

🔎 Proposed refactor to batch presigned URL generation
 private Map<Long, String> getFirstImageMapForPhotoAlbums(List<Long> albumIds) {
     if (albumIds == null || albumIds.isEmpty()) {
         return Collections.emptyMap();
     }
 
     // 배치로 대표 이미지 조회
     List<Image> firstImages =
             imageRepository.findFirstByContentIds(albumIds, FilePath.photoAlbum);
 
-    Map<Long, String> result = new HashMap<>();
-
-    for (Image img : firstImages) {
-        String presignedUrl = imageService
-                .getImages(List.of(img), img.getMemberId())
-                .get(0)
-                .getPresignedUrl();
-
-        result.put(img.getContentId(), presignedUrl);
-    }
-    return result;
+    if (firstImages.isEmpty()) {
+        return Collections.emptyMap();
+    }
+
+    // Batch convert all images to DTOs with presigned URLs
+    // Note: Assumes all images belong to the same member, or adjust as needed
+    Long memberId = firstImages.get(0).getMemberId();
+    List<ImageResponseDTO.ImageResultWithPresignedUrlDTO> imageDtos =
+            imageService.getImages(firstImages, memberId);
+
+    return imageDtos.stream()
+            .collect(Collectors.toMap(
+                    ImageResponseDTO.ImageResultWithPresignedUrlDTO::getContentId,
+                    ImageResponseDTO.ImageResultWithPresignedUrlDTO::getPresignedUrl,
+                    (a, b) -> a
+            ));
 }

Note: This assumes images from the same batch can share a memberId for presigned URL generation. If different images require different memberId values for authorization, you'll need to adjust the batching strategy accordingly.

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d80a12c and 9731ee2.

📒 Files selected for processing (2)
  • src/main/java/cc/backend/image/entity/Image.java
  • src/main/java/cc/backend/photoAlbum/service/PhotoAlbumServiceImpl.java
🔇 Additional comments (5)
src/main/java/cc/backend/image/entity/Image.java (1)

35-35: LGTM! Documentation clarification.

The terminology update from "actor" to "casting" improves clarity in the theater/performance domain context.

src/main/java/cc/backend/photoAlbum/service/PhotoAlbumServiceImpl.java (4)

135-138: LGTM! Clean preparation for batch query.

Extracting album IDs upfront is the correct approach for the N+1 prevention strategy implemented below.


151-163: LGTM! Efficient bulk DTO conversion with presigned URLs.

The empty map guard and batch conversion of images to DTOs with presigned URLs is well-implemented. This centralizes the presigned URL generation instead of calling it per-album.


166-178: LGTM! Clean DTO assembly using pre-fetched data.

The mapping correctly uses the pre-fetched imageDtoMap. Note that imageDtoMap.get(album.getId()) will return null for albums without images, which is passed to imageResultWithPresignedUrlDTO. This appears intentional based on the DTO structure.


140-148: Batch optimization is sound; merge function is defensive but unnecessary.

The query findFirstByContentIds uses a subquery i.id = (SELECT MIN(i2.id) FROM Image i2 WHERE i2.contentId = i.contentId) to guarantee exactly one Image per contentId. The merge function (a, b) -> a is therefore redundant and can be removed in favor of the more standard pattern used elsewhere (e.g., line 362), which collects directly to a Map<Long, Image> without mapping.

@sweatbuckets sweatbuckets merged commit aee717e into develop Dec 30, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants