해결된 질문
작성
·
112
·
수정됨
0
아래코드 첨부 하였구요, readAllInfiniteScroll 부분 secondPage 출력 부분에 getParentCommentId 조건 체크 부분에 진입이 되서 그런지, 부모, 하위 댓글 위치가 다르게 출력 됩니다.
강의자료에 있는걸로 이식 해봐도 동일한 증상 나옵니다. 출력 부분은 각 함수마다 하단에 기입 해놨습니다
음 그니까, readAll() 부분은 부모, 자식 구분되서 잘나오는데 무한스크롤 부분에서는 기대값은 아래처럼 첫번째 첨부한 기대값과 같아야 하는데 실제 로직에서 출력되는 부분은 다르게 출력 되는거같습니다. 어떤 부분을 확인 해봐야 할가요??
firstPage
comment.getCommentId() = 179060865682051072
comment.getCommentId() = 179060867179417600
comment.getCommentId() = 179060867334606848
comment.getCommentId() = 179061928581599232
comment.getCommentId() = 179061929433042944
comment.getCommentId() = 179061929709867008
secondPage
comment.getCommentId() = 179065967874379776
comment.getCommentId() = 179065968025374733
comment.getCommentId() = 179065967874379777
comment.getCommentId() = 179065968008597505
@Test
void readAll() {
CommentPageResponse response = restClient.get()
.uri("/v1/comments?articleId=1&page=1&pageSize=10")
.retrieve()
.body(CommentPageResponse.class);
System.out.println("response.getCommentCount() = " + response.getCommentCount());
for (CommentResponse comment : response.getComments()) {
if (!comment.getCommentId().equals(comment.getParentCommentId())) {
System.out.print("\t");
}
System.out.println("comment.getCommentId() = " + comment.getCommentId());
}
/**
* 1번 페이지 수행 결과
comment.getCommentId() = 179060865682051072
comment.getCommentId() = 179060867179417600
comment.getCommentId() = 179060867334606848
comment.getCommentId() = 179061928581599232
comment.getCommentId() = 179061929433042944
comment.getCommentId() = 179061929709867008
comment.getCommentId() = 179065967874379776
comment.getCommentId() = 179065968025374733
comment.getCommentId() = 179065967874379777
comment.getCommentId() = 179065968008597505
*/
}
@Test
void readAllInfiniteScroll() {
List<CommentResponse> responses1 = restClient.get()
.uri("/v1/comments/infinite-scroll?articleId=1&pageSize=5")
.retrieve()
.body(new ParameterizedTypeReference<List<CommentResponse>>() {
});
System.out.println("firstPage");
for (CommentResponse comment : responses1) {
if (!comment.getCommentId().equals(comment.getParentCommentId())) {
System.out.print("\t");
}
System.out.println("comment.getCommentId() = " + comment.getCommentId());
}
Long lastParentCommentId = responses1.getLast().getParentCommentId();
Long lastCommentId = responses1.getLast().getCommentId();
List<CommentResponse> responses2 = restClient.get()
.uri("/v1/comments/infinite-scroll?articleId=1&pageSize=6&lastParentCommentId=%s&lastCommentId=%s"
.formatted(lastParentCommentId, lastCommentId))
.retrieve()
.body(new ParameterizedTypeReference<List<CommentResponse>>() {
});
System.out.println("secondPage");
for (CommentResponse comment : responses2) {
if (!comment.getCommentId().equals(comment.getParentCommentId())) {
System.out.print("\t");
}
System.out.println("comment.getCommentId() = " + comment.getCommentId());
}
/**
firstPage
comment.getCommentId() = 179060865682051072
comment.getCommentId() = 179060867179417600
comment.getCommentId() = 179060867334606848
comment.getCommentId() = 179061928581599232
comment.getCommentId() = 179061929433042944
secondPage
comment.getCommentId() = 179061929709867008
comment.getCommentId() = 179065967874379776
comment.getCommentId() = 179065968025374733
comment.getCommentId() = 179065967874379777
comment.getCommentId() = 179065968008597505
comment.getCommentId() = 179065967874379778
*/
}
답변 2
0
MinKyu Song님, 안녕하세요!
결과가 다르다는게 어떤 말씀이실까요?
처음 올려주신건 첫페이지를 그냥 6개 출력해주신 것이고,
firstPage
comment.getCommentId() = 179060865682051072
comment.getCommentId() = 179060867179417600
comment.getCommentId() = 179060867334606848
comment.getCommentId() = 179061928581599232
comment.getCommentId() = 179061929433042944
comment.getCommentId() = 179061929709867008
secondPage
comment.getCommentId() = 179065967874379776
comment.getCommentId() = 179065968025374733
comment.getCommentId() = 179065967874379777
comment.getCommentId() = 179065968008597505
테스트 아래에 기입해주신 부분들도 모두 동일한 결과로 보입니다.
/**
* 1번 페이지 수행 결과
comment.getCommentId() = 179060865682051072
comment.getCommentId() = 179060867179417600
comment.getCommentId() = 179060867334606848
comment.getCommentId() = 179061928581599232
comment.getCommentId() = 179061929433042944
comment.getCommentId() = 179061929709867008
comment.getCommentId() = 179065967874379776
comment.getCommentId() = 179065968025374733
comment.getCommentId() = 179065967874379777
comment.getCommentId() = 179065968008597505
*/
/**
firstPage
comment.getCommentId() = 179060865682051072
comment.getCommentId() = 179060867179417600
comment.getCommentId() = 179060867334606848
comment.getCommentId() = 179061928581599232
comment.getCommentId() = 179061929433042944
secondPage
comment.getCommentId() = 179061929709867008
comment.getCommentId() = 179065967874379776
comment.getCommentId() = 179065968025374733
comment.getCommentId() = 179065967874379777
comment.getCommentId() = 179065968008597505
comment.getCommentId() = 179065967874379778
*/
다르다고 말씀 주신 부분이 어떤 내용일까요!?
앞전에 올린건 노트북에서 테스트하다보니 정리가 덜된 부분인거같아 송구 스럽네요, 이번건 데탑에서 다시 해봣는데 첫번째 출력 부분은 readAll 이고
두번째 출력 부분은 readAllInfiniteScroll 출력된 결과입니다. 다름이 아니고
readAllInfiniteScroll 출력 부분에 firstPage에서 comment.getCommentId() = 179202646385852418 이부분에 자식인 secondPage에 comment.getCommentId() = 179202646440378369 출력되는 구조 인거 같아서요, 강사님 강의에서는 firstPage,secondPage 각각 5개식 부모,자식 댓글 구조로 출력이 되고 있는데, 제가 테스트한 결과에서는 secondPage에서 부모댓글부터 출력 되는게 아닌 자식댓글 출력되는거같은데, 어디가 문제인지 알수 있을까요??, 혹시 몰라서 강사님쪽 강의에서 테스트한 출력 결과도 첨부 해보았습니다.
/** readAll 출력부분
* 1번 페이지 수행 결과
comment.getCommentId() = 179202646385852416
comment.getCommentId() = 179202646440378374
comment.getCommentId() = 179202646385852417
comment.getCommentId() = 179202646440378372
comment.getCommentId() = 179202646385852418
comment.getCommentId() = 179202646440378369
comment.getCommentId() = 179202646385852419
comment.getCommentId() = 179202646440378377
comment.getCommentId() = 179202646385852420
comment.getCommentId() = 179202646440378375
*/
/** readAllInfiniteScroll 출력 부분
firstPage
comment.getCommentId() = 179202646385852416
comment.getCommentId() = 179202646440378374
comment.getCommentId() = 179202646385852417
comment.getCommentId() = 179202646440378372
comment.getCommentId() = 179202646385852418
secondPage
comment.getCommentId() = 179202646440378369
comment.getCommentId() = 179202646385852419
comment.getCommentId() = 179202646440378377
comment.getCommentId() = 179202646385852420
comment.getCommentId() = 179202646440378375
*/
편히 문의 주셔도 괜찮습니다!
다시 올려주신 결과 확인해보았는데요, 아무 이상 없는 결과입니다!
readAll과 readAllInfiniteScroll과 결과가 동일하다면, 그게 맞습니다!
그냥 제 로컬 환경에서 가지고 있는 데이터셋과 MinKyu Song님 로컬 환경에서 가지고 있는 데이터셋이 다를 뿐입니다.
어차피 사용자 화면에서는 readAllInfiniteScroll의 1+2번 페이지 모두 연달아 보여주기 때문에, 계층형 데이터에 대해 계층 관계가 정확히 나타난게 맞습니다.
MinKyu Song님 로컬 데이터셋에는 readAllInfiniteScroll의 2번 페이지의 첫번째 데이터가 2뎁스인 것 뿐입니다!
5개씩 페이징한 결과로 문제 없는 상황입니다.
0
안녕하세요, 인프런 AI 인턴입니다. MinKyu Song님.
테스트 코드에서 무한 스크롤의 결과가 기대한 대로 정렬되지 않아 어려움을 겪고 계신 것 같습니다. 무한 스크롤 구현에서 종종 발생하는 문제로, 데이터의 정렬과 페이지네이션 논리가 기대한 방식대로 작동하지 않는 경우가 있습니다. 아래에 몇 가지 검토해야 할 사항과 해결 방법을 제시해 드립니다.
정렬 기준 확인:
commentId
나 createdAt
필드를 기반으로 정렬하는 것이 일반적입니다. 출력이 예상치 못하게 정렬되는 문제는 서버에서의 기본 정렬 설정이 없어서 발생할 수 있습니다.마지막 댓글 파라미터 확인:
lastParentCommentId
및 lastCommentId
를 기반으로 다음 무한 스크롤 호출을 할 때, 이 조건들이 올바르게 작동하는지 확인해보세요. 이는 다음 페이지의 데이터 시작점을 결정하는 데 있어 매우 중요합니다.responses1
의 마지막 항목의 getParentCommentId()
와 getCommentId()
를 잘 활용하고 있는지 점검하세요.API 호출 시 파라미터 검증:
formatted
메소드를 사용하는 파라미터와 실제 요청된 URL이 일치하는지 확인하셔야 합니다. 잘못된 URL 구조로 인해 예상치 못한 결과가 반환될 수 있습니다.데이터베이스 및 캐싱 확인:
아래의 링크를 통해 유사한 문제를 겪었던 다른 사용자들의 질문을 확인하여 추가적인 해결 힌트를 찾아볼 수 있습니다:
위 방법들을 통해 문제가 해결되지 않을 경우, 추가적인 로그를 통해 어떤 식으로 요청과 응답이 처리되고 있는지 확인하여 원인을 상세히 분석하시는 것도 도움이 될 것입니다.
저는 질문자님의 이해를 돕고자 지식공유자님의 기존 답변을 참고하여 유사한 답변 링크를 추천해드리고 있습니다. 현재 베타 기능으로 답변이 만족스럽지 않을 수 있는 점 양해 부탁드립니다. 🙏
추가적으로 궁금한 점이 있으시면, 이어서 질문해 주세요. 곧 지식공유자께서 답변해 주실 것입니다.
제가 테스트 하다가 일목요연하게 작성을 못한점이 있는거같습니다.
다시 테스트 해보고 결과 다시 작성해서 올려 보도록 하겠습니다.