Repository navigation
bug: 사용자 목록·발급이력 페이지네이션에 안정 정렬 키 추가 (#65) - #73
Merged
Merged
Conversation
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configuration
📒 Files selected for processing (5)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
개요
목록 조회 두 곳에 안정 정렬(stable sort) 키가 없어서 페이지를 넘길 때 같은 행이 두 번 나오거나 아예 누락될 수 있었다.
GET /api/admins(사용자 목록):Pageable에Sort가 아예 없었다. 정렬이 없으면 DB가 행 순서를 보장하지 않으므로 페이지마다 순서가 달라지고, 경계에 걸친 행이 중복/누락된다.GET /api/issuance-histories(발급 이력):order by i.issuedAt desc만 있어 동일issuedAt동점 처리가 없었다. 같은 초에 여러 건이 발급되면 같은 문제가 생긴다.human/search는 이미Sort.by("humanId")로 막아두고 주석까지 달려 있었다. 같은 방어를 나머지 두 곳에 맞췄다.Closes #65
변경 내용
admin/service/QueryUserListServicePageNumber.toPageable(page, size, Sort.by(ASC, "id"))로 정렬 키를 넣었다.Admin.id**로 잡았다.Admin은@MapsId로user_id를 PK로 쓰므로id가 곧 사용자 ID이고 유일하다.admin테이블 자체 컬럼이라User로 조인을 타지 않는다.user.name은 동명이인에서 다시 불안정해져 2차 키 없이는 쓸 수 없으므로 쓰지 않았다.certificate/repository/CertificateIssuedRepository.searchHistoriesorder by i.issuedAt desc→order by i.issuedAt desc, i.certificateIssuedId desc. 1차 정렬(발급 최신순)은 그대로고, 동점일 때만 유일 키로 순서를 확정한다.human/search는 손대지 않았다.테스트
전체 88개 전부 통과 (기존 80 + 추가 8).
추가한 테스트 8개:
admin/UserListPagingApiTest(3) — MockMvc 통합size보다 많은 데이터(7건, size 3)를 만들고 1·2페이지를 받아 식별자 집합이 겹치지 않는지 확인admin/service/QueryUserListServiceTest(2) — MockitoPageable을 캡처해 정렬이 실제로 실려 나가는지 단언. H2/Postgres가 우연히 삽입 순서를 돌려주면 통합 테스트만으로는 정렬 누락이 안 잡히기 때문에 둔 가드다 (정렬을 되돌리면 이 둘이 바로 깨지는 것을 확인했다).domain/certificate/IssuanceHistoryPagingApiTest(3) — MockMvc 통합issuedAt이 전부 동일한 발급 7건을 만들어 1·2페이지 중복 없음 / 전체 합집합 일치 검증certificateIssuedId내림차순으로 안정 정렬되는지 검증 (2차 정렬 키를 빼면 이 테스트가 깨지는 것을 확인했다)FE / 리뷰어가 알아야 할 것
PageResponse봉투, 필드명, 상태 코드)은 그대로다. 바뀐 것은 행의 순서뿐이다.GET /api/admins: 기존에는 순서가 비결정적이었고, 이제 사용자 ID 오름차순으로 고정된다.GET /api/issuance-histories: 발급 최신순은 그대로이고, 같은 시각 동점일 때만 발급 ID 내림차순(= 나중에 저장된 건이 먼저)으로 고정된다.schema.sql변경도 없다.Sort.by("user.name").and(Sort.by("id"))처럼 2차 키를 붙여 바꿀 수 있다(조인이 필요해@EntityGraph와의 조합을 확인해야 한다). 이번 PR 범위는 "불안정한 페이지네이션 수정"이라 UX 정렬 기준 변경은 하지 않았다.