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

Api: ✨ Chat History Search API (redis score system changed) #195

Merged
merged 16 commits into from
Nov 10, 2024

Conversation

psychology50
Copy link
Member

작업 이유

  • Implement a Chat History Retrieval API by Chat Room
  • Modify the storage method for chat history in Redis.

작업 사항

1️⃣ Api Specification

  • request
    • url: GET /v2/chat-rooms/{chatRoomId}/chats?chatRoomId=&lastMessageId=&size=
      • pre-condition: authenticated user, chat room accessible by userId
      • parameter
        • chatRoomId
        • lastMessageId: oldest message ID read by the client
        • size: content size (Optional)
  • response
    {
      "code": ""
      "data": {
        "chats": {
          "contents": [
            {
              "chatRoomId": 0,
              "chatId": 0,
              "content": "string",
              "contentType": "TEXT",
              "categoryType": "NORMAL",
              "createdAt": "2024-11-10 14:05:10",
              "senderId": 0
            },
          ],
          "currentPageNumber": 0,
          "pageSize": 0,
          "numberOfElements": 0,
          "hasNext": true
      }
    }

2️⃣ Redis Sorted Set Score Type Problem

image

The issue was first discovered during integration testing.
With N data entries saved and querying the oldest message ID as lastMessageId, it should return 0.

image

However, the same lastMessageId messages kept appearing.

image
image
image

Revealing that Redis' sorted set score type only supports double values, causing precision loss for the long type chatId used as a score.
This was resolved by implementing lexicographical sorting, using a format of {timestamp}:{counter} as follows:

/**
* TSID를 lexicographical sorting이 가능한 형태의 문자열로 변환
* format: {timestamp부분:16진수}:{counter부분:4자리}
*/
private String formatTsidKey(long tsid) {
    String tsidStr = String.valueOf(tsid);

    String timestamp = tsidStr.substring(0, tsidStr.length() - COUNTER_DIGITS);
    String counter = tsidStr.substring(tsidStr.length() - COUNTER_DIGITS);

    return timestamp + ":" + counter;
}

리뷰어가 중점적으로 확인해야 하는 부분

  • Potential performance degradation from the new method, but not critical given expected traffic.
  • Code has seen many rapid changes; feedback on areas needing improvement is appreciated.

발견한 이슈

  • Many commands with REV are now deprecated in Redis, yet Data Redis still supports them, so no changes were made.
  • Due to complexity, we have decided to clear existing chat history with the iOS team's consent.

@psychology50 psychology50 added enhancement New feature or request fix 기능 수정 labels Nov 10, 2024
@psychology50 psychology50 self-assigned this Nov 10, 2024
@psychology50 psychology50 merged commit bf2a278 into dev Nov 10, 2024
1 check passed
@psychology50 psychology50 deleted the feat/PW-607-get-chat-history branch November 10, 2024 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request fix 기능 수정
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant