-
Notifications
You must be signed in to change notification settings - Fork 1
[FIX] 사진첩 전체 조회 무한스크롤 updatedAt 인자 추가 #146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
📝 WalkthroughWalkthroughIntroduces timestamp-aware cursor pagination for photo album retrieval by adding a Changes
Sequence DiagramsequenceDiagram
participant Client
participant Controller as PhotoAlbumController
participant Service as PhotoAlbumService
participant Repository as PhotoAlbumRepository
participant DTO as ScrollMemberPhotoAlbumDTO
Client->>Controller: GET /api/albums?cursorId=X&cursorUpdatedAt=T&size=Y
Controller->>Service: getAllRecentPhotoAlbumList(cursorId, cursorUpdatedAt, size)
Service->>Repository: findNextAlbums(cursorId, cursorUpdatedAt, pageable)
Repository-->>Service: List<PhotoAlbum> (paginated results)
Service->>Service: extract last item's id & updatedAt
Service->>DTO: build ScrollMemberPhotoAlbumDTO with nextCursorId + nextCursorUpdatedAt
Service-->>Controller: ScrollMemberPhotoAlbumDTO
Controller-->>Client: JSON response with nextCursorId & nextCursorUpdatedAt
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/main/java/cc/backend/photoAlbum/repository/PhotoAlbumRepository.java`:
- Around line 42-47: The WHERE clause in PhotoAlbumRepository's findNextAlbums
uses only "cursorId IS NULL" to detect initial requests which can mis-handle
cases where cursorId and cursorUpdatedAt are not provided together; update the
predicate to treat the cursor as absent only when both parameters are null
(e.g., "(:cursorId IS NULL AND :cursorUpdatedAt IS NULL) OR ...") and ensure the
subsequent comparison branch uses both cursorUpdatedAt and cursorId (p.updatedAt
< :cursorUpdatedAt OR (p.updatedAt = :cursorUpdatedAt AND p.id < :cursorId)) so
the composite cursor is applied atomically.
🧹 Nitpick comments (1)
src/main/java/cc/backend/photoAlbum/service/PhotoAlbumServiceImpl.java (1)
303-304: Consider extracting the repeated condition and last-element access.The condition
hasNext && !limitedAlbums.isEmpty()and the last-element access are duplicated. A minor refactor could improve readability.♻️ Suggested refactor
// 다음 커서 설정 boolean hasNext = albums.size() > size; - Long nextCursorId = (hasNext && !limitedAlbums.isEmpty()) ? limitedAlbums.get(limitedAlbums.size() - 1).getId() : null; - LocalDateTime nextCursorUpdatedAt = (hasNext && !limitedAlbums.isEmpty()) ? limitedAlbums.get(limitedAlbums.size() - 1).getUpdatedAt() : null; + Long nextCursorId = null; + LocalDateTime nextCursorUpdatedAt = null; + if (hasNext && !limitedAlbums.isEmpty()) { + PhotoAlbum lastAlbum = limitedAlbums.get(limitedAlbums.size() - 1); + nextCursorId = lastAlbum.getId(); + nextCursorUpdatedAt = lastAlbum.getUpdatedAt(); + }
| WHERE (:cursorId IS NULL | ||
| OR p.updatedAt < :cursorUpdatedAt | ||
| OR (p.updatedAt = :cursorUpdatedAt AND p.id < :cursorId)) | ||
| ORDER BY p.updatedAt DESC, p.id DESC | ||
| """) | ||
| List<PhotoAlbum> findNextAlbums(@Param("cursorId") Long cursorId, Pageable pageable); | ||
| """) | ||
| List<PhotoAlbum> findNextAlbums(@Param("cursorId") Long cursorId, @Param("cursorUpdatedAt") LocalDateTime cursorUpdatedAt, Pageable pageable); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cursor null-check logic may cause incorrect filtering on first page.
The query only checks cursorId IS NULL to determine if this is the initial request. However, both cursorId and cursorUpdatedAt form a composite cursor. If only one is null while the other has a value (due to client error or API misuse), the query may produce unexpected results.
Consider checking both cursor parameters together:
🔧 Proposed fix
`@Query`("""
SELECT p
FROM PhotoAlbum p
LEFT JOIN p.amateurShow a
- WHERE (:cursorId IS NULL
+ WHERE ((:cursorId IS NULL OR :cursorUpdatedAt IS NULL)
OR p.updatedAt < :cursorUpdatedAt
OR (p.updatedAt = :cursorUpdatedAt AND p.id < :cursorId))
ORDER BY p.updatedAt DESC, p.id DESC
""")🤖 Prompt for AI Agents
In `@src/main/java/cc/backend/photoAlbum/repository/PhotoAlbumRepository.java`
around lines 42 - 47, The WHERE clause in PhotoAlbumRepository's findNextAlbums
uses only "cursorId IS NULL" to detect initial requests which can mis-handle
cases where cursorId and cursorUpdatedAt are not provided together; update the
predicate to treat the cursor as absent only when both parameters are null
(e.g., "(:cursorId IS NULL AND :cursorUpdatedAt IS NULL) OR ...") and ensure the
subsequent comparison branch uses both cursorUpdatedAt and cursorId (p.updatedAt
< :cursorUpdatedAt OR (p.updatedAt = :cursorUpdatedAt AND p.id < :cursorId)) so
the composite cursor is applied atomically.
#이슈번호,#이슈번호Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.