Skip to content
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

Merged
merged 6 commits into from
Aug 31, 2024

Conversation

min429
Copy link
Collaborator

@min429 min429 commented Aug 28, 2024

📄 변경 사항

  • 페이징 �방식을 오프셋 기반에서 커서 기반으로 변경합니다.

밑의 글을 참고해서 구현했습니다.
커서 기반 페이지네이션 (Cursor-based Pagination) 구현하기

@min429 min429 requested a review from rlarltj August 28, 2024 15:50
@min429 min429 self-assigned this Aug 28, 2024
@min429 min429 changed the title Issue 208 feat: 페이징 방식을 오프셋 기반에서 커서 기반으로 변경한다. Aug 29, 2024
Comment on lines 33 to 37
StringTemplate nextCursor = Expressions.stringTemplate(
"CONCAT(DATE_FORMAT({0}, '%Y%m%d%H%i%S'), LPAD(CAST({1} AS STRING), 6, '0'))",
updatedAt,
id
);
Copy link
Member

Choose a reason for hiding this comment

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

Q. updatedA을 사용하는 이유가 있을까요 ?

Copy link
Collaborator Author

@min429 min429 Aug 30, 2024

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을 가져오고 나서 그 뒤의 값들을 읽을 수 없게 된다고 생각했습니다.
image

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

생성일 기준으로 정렬하는거면, id값도 어짜피 생성일 순서랑 같을 것 같아서 cursor를 id로 해도 상관없을 것 같은데, 업데이트 날짜 기준으로 정렬할 때는 두가지 다 고려해야하지 않을까 싶네요

@min429 min429 merged commit fd98935 into main Aug 31, 2024
1 check passed
@min429 min429 deleted the ISSUE-208 branch August 31, 2024 10:55
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.

2 participants