-
Notifications
You must be signed in to change notification settings - Fork 1
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
feat: 페이징 방식을 오프셋 기반에서 커서 기반으로 변경한다. #44
Conversation
StringTemplate nextCursor = Expressions.stringTemplate( | ||
"CONCAT(DATE_FORMAT({0}, '%Y%m%d%H%i%S'), LPAD(CAST({1} AS STRING), 6, '0'))", | ||
updatedAt, | ||
id | ||
); |
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.
Q. updatedA을 사용하는 이유가 있을까요 ?
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.
커서 페이징은 정렬할 컬럼에 중복된 값이 존재하면 안되고, 순차적이어야 하기 때문에 updateAt 기준으로 정렬하면서 중복을 피하기 위해 boardId와 updateAt을 합쳐서 cursor를 만들었습니다.
정렬 기준이 updatedAt -> id 순서인데, 만약 cursor를 id로만 할 경우, id값을 기준으로 정렬되어있지 않기 때문에 값을 제대로 가져오지 못할 수도 있다고 판단했습니다.
예를들어, 데이터가 다음 그림과 같은경우, 만약 id만 cursor로 쓴다면 size가 1일때, id 3을 가져오고 나서 그 뒤의 값들을 읽을 수 없게 된다고 생각했습니다.
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.
생성일 기준으로 정렬하는거면, id값도 어짜피 생성일 순서랑 같을 것 같아서 cursor를 id로 해도 상관없을 것 같은데, 업데이트 날짜 기준으로 정렬할 때는 두가지 다 고려해야하지 않을까 싶네요
📄 변경 사항
밑의 글을 참고해서 구현했습니다.
커서 기반 페이지네이션 (Cursor-based Pagination) 구현하기