Skip to content

[Bug/#483] 저장 api 수정 - #485

Merged
leesumin0526 merged 1 commit into
mainfrom
dev
Feb 21, 2026
Merged

[Bug/#483] 저장 api 수정#485
leesumin0526 merged 1 commit into
mainfrom
dev

Conversation

@leesumin0526

@leesumin0526 leesumin0526 commented Feb 21, 2026

Copy link
Copy Markdown
Collaborator

PR 타입(하나 이상의 PR 타입을 선택해주세요)

  • 기능 추가
  • 기능 삭제
  • 버그 수정
  • 의존성, 환경 변수, 빌드 관련 코드 업데이트
  • 리팩터링

반영 브랜치

dev -> main

작업 내용

테스트 결과

ex) 베이스 브랜치에 포함되기 위한 코드는 모두 정상적으로 동작해야 합니다. 결과물에 대한 스크린샷, GIF, 혹은 라이브

Summary by CodeRabbit

버그 수정

  • 좋아요 표시한 피드 조회 시 개별 피드의 저장 여부가 사용자의 실제 저장 상태에 따라 정확하게 표시되도록 수정되었습니다. 이전에는 모든 피드가 저장된 것으로 잘못 표시되던 문제를 해결했습니다.

* [FIX/#483] 피드 저장 상태 표시 에러 수정

* [FIX/#483] OpenAI 사용하는 방식으로 롤백
@leesumin0526 leesumin0526 self-assigned this Feb 21, 2026
@coderabbitai

coderabbitai Bot commented Feb 21, 2026

Copy link
Copy Markdown

개요

getLikedFeedsWithPaging 메서드에서 사용자의 저장된 피드 ID를 사전에 조회하여 각 피드의 isSaved 플래그를 정확하게 결정하도록 수정했습니다. 기존에는 항상 true로 설정되던 로직을 실제 저장 여부 기반으로 변경했습니다.

변경사항

코호트 / 파일 요약
피드 쿼리 서비스
src/main/java/stackpot/stackpot/feed/service/FeedQueryServiceImpl.java
getLikedFeedsWithPaging 메서드에서 feedSaveRepository.findFeedIdsByUserId()를 통해 저장된 피드 ID를 조회하고, isSaved 플래그를 항상 true에서 실제 저장 여부(savedFeedIds.contains(feedId))로 변경.

예상 코드 리뷰 난이도

🎯 2 (단순) | ⏱️ ~10분

추천 레이블

bug

🐰 저장된 피드의 진실을 찾아서,
거짓 true를 걷어내고,
참된 상태를 밝혀내니,
사용자의 맘이 한결 편하네!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title '[Bug/#483] 저장 api 수정' is partially related to the changeset. It references a bug fix about the save API, which aligns with the code changes that fix the isSaved flag calculation in feed queries. However, the title is quite generic and doesn't clearly specify that the fix involves correcting the isSaved determination logic in feed save status display.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch dev

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (3)
src/main/java/stackpot/stackpot/feed/service/FeedQueryServiceImpl.java (3)

205-207: 주석 처리된 코드 제거 권장

아래 코드 블록이 주석으로 남아 있습니다. 대체 로직이 이미 적용되어 있으므로 제거하는 것이 좋습니다.

♻️ 제안
-//        List<Feed> feeds = (nextCursor == null)
-//                ? feedRepository.findByUser_Id(userId, pageable)
-//                : feedRepository.findByUserIdAndFeedIdBefore(userId, nextCursor, pageable);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/java/stackpot/stackpot/feed/service/FeedQueryServiceImpl.java`
around lines 205 - 207, The commented-out conditional assignment for feeds in
FeedQueryServiceImpl (the block using feedRepository.findByUser_Id and
feedRepository.findByUserIdAndFeedIdBefore with nextCursor) is obsolete and
should be removed; open the method in FeedQueryServiceImpl where the variable
nextCursor and List<Feed> feeds are handled and delete that commented code block
so only the active logic remains (remove the lines containing
feedRepository.findByUser_Id(...) and
feedRepository.findByUserIdAndFeedIdBefore(...)).

129-138: [추천 개선] 스트림 내 countByFeed N+1 쿼리 → 배치 조회로 전환 권장

getPreViewFeeds (Line 134), getFeedsByUserId (Line 224), getFeeds (Line 269), searchByUserIdByKeyword (Line 501) 등에서 feedSaveRepository.countByFeed(feed) 또는 countByFeedId를 스트림 내에서 per-feed 호출하고 있어 N+1 쿼리가 발생합니다. getLikedFeedsWithPaging에서 이미 countSavesByFeedIds(feedIds)로 배치 조회하는 패턴을 사용 중이므로, 다른 메서드에도 동일한 방식을 적용하는 것을 권장합니다.

♻️ 개선 예시 (getPreViewFeeds 기준)
+ List<Long> feedPageIds = feedResults.stream()
+         .map(Feed::getFeedId)
+         .collect(Collectors.toList());
+ Map<Long, Integer> saveCountMap = feedSaveRepository.countSavesByFeedIds(feedPageIds).stream()
+         .collect(Collectors.toMap(
+                 row -> (Long) row[0],
+                 row -> ((Long) row[1]).intValue()
+         ));

  List<FeedResponseDto.FeedDto> feedDtoList = feedResults.stream()
          .map(feed -> {
              boolean isOwner = (user != null) && Objects.equals(user.getId(), feed.getUser().getUserId());
              Boolean isLiked = (isAuthenticated && userId != null) ? likedFeedIds.contains(feed.getFeedId()) : null;
              Boolean isSaved = (isAuthenticated && userId != null) ? savedFeedIds.contains(feed.getFeedId()) : null;
-             int saveCount = feedSaveRepository.countByFeed(feed);
+             int saveCount = saveCountMap.getOrDefault(feed.getFeedId(), 0);

              return feedConverter.feedDto(feed, isOwner, isLiked, isSaved, saveCount);
          })
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/java/stackpot/stackpot/feed/service/FeedQueryServiceImpl.java`
around lines 129 - 138, The stream mapping in feedDtoList calls
feedSaveRepository.countByFeed(feed) per item causing N+1 queries; change to
batch-fetch save counts before mapping: collect feedIds from feedResults, call
the existing batch method (e.g., countSavesByFeedIds(feedIds) or add a
repository method that returns Map<FeedId,Integer>), build a Map<feedId,
saveCount>, then in the feedResults.stream().map(...) use
map.get(feed.getFeedId()) (fallback 0) instead of countByFeed; apply the same
pattern used in getLikedFeedsWithPaging to getPreViewFeeds, getFeedsByUserId,
getFeeds, searchByUserIdByKeyword and keep calling feedConverter.feedDto(feed,
isOwner, isLiked, isSaved, saveCount).

342-345: [선택적 개선] 현재 페이지 feedIds 범위로 쿼리 스코프 축소 고려

findFeedIdsByUserId는 유저의 전체 좋아요/저장 ID를 반환하지만, 실제로 필요한 것은 현재 페이지의 feedIds에 해당하는 항목만입니다. 특히 countSavesByFeedIds(feedIds)가 이미 스코프 쿼리 패턴을 사용하고 있으므로, 같은 방식으로 좋아요/저장 ID 조회도 최적화할 수 있습니다. 인터랙션이 많은 사용자일수록 불필요한 데이터 로드를 줄일 수 있습니다.

♻️ 개선 예시
- List<Long> likedFeedIds = feedLikeRepository.findFeedIdsByUserId(user.getId());
- // 미리 저장한 피드 ID 조회
- List<Long> savedFeedIds = feedSaveRepository.findFeedIdsByUserId(user.getId());
+ // 현재 페이지 feedIds 범위 내에서만 조회
+ List<Long> likedFeedIds = feedLikeRepository.findFeedIdsByUserIdAndFeedIds(user.getId(), feedIds);
+ List<Long> savedFeedIds = feedSaveRepository.findFeedIdsByUserIdAndFeedIds(user.getId(), feedIds);

(리포지토리에 findFeedIdsByUserIdAndFeedIds 메서드 추가 필요)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/java/stackpot/stackpot/feed/service/FeedQueryServiceImpl.java`
around lines 342 - 345, The current calls to
feedLikeRepository.findFeedIdsByUserId and
feedSaveRepository.findFeedIdsByUserId load all interactions for the user;
restrict the query to only the current page's feedIds by adding and using
repository methods like findFeedIdsByUserIdAndFeedIds(userId, feedIds) and
findSavedFeedIdsByUserIdAndFeedIds(userId, feedIds) (or a single method name
consistent with your repo), then replace the two calls in FeedQueryServiceImpl
(the variables likedFeedIds and savedFeedIds) to pass the existing feedIds
collection so only relevant IDs are fetched.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/main/java/stackpot/stackpot/feed/service/FeedQueryServiceImpl.java`:
- Around line 205-207: The commented-out conditional assignment for feeds in
FeedQueryServiceImpl (the block using feedRepository.findByUser_Id and
feedRepository.findByUserIdAndFeedIdBefore with nextCursor) is obsolete and
should be removed; open the method in FeedQueryServiceImpl where the variable
nextCursor and List<Feed> feeds are handled and delete that commented code block
so only the active logic remains (remove the lines containing
feedRepository.findByUser_Id(...) and
feedRepository.findByUserIdAndFeedIdBefore(...)).
- Around line 129-138: The stream mapping in feedDtoList calls
feedSaveRepository.countByFeed(feed) per item causing N+1 queries; change to
batch-fetch save counts before mapping: collect feedIds from feedResults, call
the existing batch method (e.g., countSavesByFeedIds(feedIds) or add a
repository method that returns Map<FeedId,Integer>), build a Map<feedId,
saveCount>, then in the feedResults.stream().map(...) use
map.get(feed.getFeedId()) (fallback 0) instead of countByFeed; apply the same
pattern used in getLikedFeedsWithPaging to getPreViewFeeds, getFeedsByUserId,
getFeeds, searchByUserIdByKeyword and keep calling feedConverter.feedDto(feed,
isOwner, isLiked, isSaved, saveCount).
- Around line 342-345: The current calls to
feedLikeRepository.findFeedIdsByUserId and
feedSaveRepository.findFeedIdsByUserId load all interactions for the user;
restrict the query to only the current page's feedIds by adding and using
repository methods like findFeedIdsByUserIdAndFeedIds(userId, feedIds) and
findSavedFeedIdsByUserIdAndFeedIds(userId, feedIds) (or a single method name
consistent with your repo), then replace the two calls in FeedQueryServiceImpl
(the variables likedFeedIds and savedFeedIds) to pass the existing feedIds
collection so only relevant IDs are fetched.

@leesumin0526
leesumin0526 merged commit e662e92 into main Feb 21, 2026
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.

1 participant