refactor: 피드 페이지네이션을 offset기반에서 cursor방식으로 전환#371
Merged
Conversation
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.
📌 관련 이슈
피드 페이징 조회를 offset 기반에서 cursor 방식으로 전환 #369
🛠️ 작업 내용
page,size를 사용하는 Offset 기반 페이징을lastId파라미터를 사용하는 Cursor 기반 페이징으로 변경했습니다.WHERE절에 복잡한 커서 조건을 동적으로 생성하는 쿼리 로직을 구현하여(university, category, pinned, createdDate, id)값을 기준으로 다음 데이터를 효율적으로 조회합니다.(university, category, pinned DESC, createdDate DESC, id DESC)순서의 복합 인덱스를 데이터베이스에 생성하여 쿼리 속도를 개선했습니다.🚀 성능 비교 (더미 데이터 100만 건 기준)
lastId=10기준 조회Offset 기반이 6.68초 걸리던 작업을 Cursor 기반은 482ms로 처리하며 약 14배의 성능 개선 효과를 보였습니다.
(Offset과 Cursor 방식 모두 최적화된 인덱스를 생성한 후의 결과입니다.)
🤔 인덱스 도입의 트레이드 오프
단점: 인덱스 용량 증가
(university, category, pinned, createdDate, id)복합 인덱스를 추가해야 합니다.기존 인덱스(
PRIMARY95.64MB,student_id36.58MB 등)와 비교했을 때 합리적인 수준의 투자로 판단됩니다.장점: 압도적인 성능 및 데이터 정합성