Skip to content

Commit 16ee824

Browse files
authored
Refactor: Preserve reading session start time for same content (#251)
1 parent 7bc21d7 commit 16ee824

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/main/java/com/linglevel/api/streak/service/ReadingSessionService.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ public class ReadingSessionService {
2323

2424
public void startReadingSession(String userId, ContentType contentType, String contentId) {
2525
String key = READING_SESSION_KEY_PREFIX + userId + READING_SESSION_KEY_SUFFIX;
26+
ReadingSession existingSession = getReadingSession(userId);
27+
28+
// 같은 작품에 대한 세션이 이미 존재하면 started 시간을 갱신하지 않음
29+
if (existingSession != null
30+
&& existingSession.getContentType().equals(contentType)
31+
&& existingSession.getContentId().equals(contentId)) {
32+
// TTL만 갱신
33+
redisTemplate.expire(key, READING_SESSION_TTL);
34+
return;
35+
}
36+
37+
// 다른 작품이거나 세션이 없으면 새로운 세션 생성
2638
ReadingSession session = ReadingSession.builder()
2739
.contentType(contentType)
2840
.contentId(contentId)

0 commit comments

Comments
 (0)