-
Notifications
You must be signed in to change notification settings - Fork 8
fix: 게시글 중복 생성 방지 #649
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
Merged
JAEHEE25
merged 3 commits into
solid-connection:develop
from
JAEHEE25:fix/640-post-duplication
Feb 12, 2026
Merged
fix: 게시글 중복 생성 방지 #649
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
8 changes: 4 additions & 4 deletions
8
src/main/java/com/example/solidconnection/cache/ThunderingHerdCachingAspect.java
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
2 changes: 1 addition & 1 deletion
2
src/main/java/com/example/solidconnection/common/config/redis/RedisConfig.java
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
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
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
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
58 changes: 58 additions & 0 deletions
58
src/main/java/com/example/solidconnection/community/post/service/PostRedisManager.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| package com.example.solidconnection.community.post.service; | ||
|
|
||
| import static com.example.solidconnection.redis.RedisConstants.POST_CREATE_PREFIX; | ||
| import static com.example.solidconnection.redis.RedisConstants.VALIDATE_POST_CREATE_TTL; | ||
| import static com.example.solidconnection.redis.RedisConstants.VALIDATE_VIEW_COUNT_KEY_PREFIX; | ||
| import static com.example.solidconnection.redis.RedisConstants.VALIDATE_VIEW_COUNT_TTL; | ||
| import static com.example.solidconnection.redis.RedisConstants.VIEW_COUNT_KEY_PREFIX; | ||
|
|
||
| import com.example.solidconnection.redis.RedisService; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class PostRedisManager { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 흩어진 |
||
|
|
||
| private final RedisService redisService; | ||
|
|
||
| public Long getPostIdFromPostViewCountRedisKey(String key) { | ||
| return Long.parseLong(key.substring(VIEW_COUNT_KEY_PREFIX.getValue().length())); | ||
| } | ||
|
|
||
| public Long getAndDeleteViewCount(String key) { | ||
| return redisService.getAndDelete(key); | ||
| } | ||
|
|
||
| public void deleteViewCountCache(Long postId) { | ||
| String key = getPostViewCountRedisKey(postId); | ||
| redisService.deleteKey(key); | ||
| } | ||
|
|
||
| public void incrementViewCountIfFirstAccess(long siteUserId, Long postId) { | ||
| String validateKey = getValidatePostViewCountRedisKey(siteUserId, postId); | ||
| boolean isFirstAccess = redisService.isPresent(validateKey, VALIDATE_VIEW_COUNT_TTL.getValue()); | ||
|
|
||
| if (isFirstAccess) { | ||
| String viewCountKey = getPostViewCountRedisKey(postId); | ||
| redisService.increaseViewCount(viewCountKey); | ||
| } | ||
| } | ||
|
|
||
| public String getPostViewCountRedisKey(Long postId) { | ||
| return VIEW_COUNT_KEY_PREFIX.getValue() + postId; | ||
| } | ||
|
|
||
| public String getValidatePostViewCountRedisKey(long siteUserId, Long postId) { | ||
| return VALIDATE_VIEW_COUNT_KEY_PREFIX.getValue() + postId + ":" + siteUserId; | ||
| } | ||
|
|
||
| public boolean isPostCreationAllowed(Long siteUserId) { | ||
| String key = getPostCreateRedisKey(siteUserId); | ||
| return redisService.isPresent(key, VALIDATE_POST_CREATE_TTL.getValue()); | ||
| } | ||
|
|
||
| public String getPostCreateRedisKey(Long siteUserId) { | ||
| return POST_CREATE_PREFIX.getValue() + siteUserId; | ||
| } | ||
| } | ||
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
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
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
2 changes: 1 addition & 1 deletion
2
src/main/java/com/example/solidconnection/scheduler/UpdateViewCountScheduler.java
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
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.
🧩 Analysis chain
🏁 Script executed:
fd "PostRedisManager.java" -t f --exec cat {}Repository: solid-connection/solid-connect-server
Length of output: 2330
🏁 Script executed:
fd "PostCommandService.java" -t f --exec cat {}Repository: solid-connection/solid-connect-server
Length of output: 6411
🏁 Script executed:
fd "RedisService.java" -t f --exec cat {}Repository: solid-connection/solid-connect-server
Length of output: 1878
🏁 Script executed:
fd "RedisConstants.java" -t f --exec cat {}Repository: solid-connection/solid-connect-server
Length of output: 789
생성 실패 시 Redis 락이 해제되지 않는 문제를 수정하세요.
문제의 원인
isPostCreationAllowed()는 Redis의 SETNX(setIfAbsent) 명령으로 5초 TTL의 락을 설정합니다.true를 반환하고, 이후 Board 조회·Post 저장·S3 이미지 업로드가 진행됩니다.사용자 영향
수정 방향
try-catch블록으로 감싸거나,PostRedisManager에 락 해제 메서드를 추가하는 방식을 권장합니다.🛠️ 제안하는 구현 예시
// 중복 생성 방지 if (!postRedisManager.isPostCreationAllowed(siteUserId)) { throw new CustomException(DUPLICATE_POST_CREATE_REQUEST); } - // 객체 생성 - Board board = boardRepository.getByCode(postCreateRequest.boardCode()); - Post post = postCreateRequest.toEntity(siteUser, board); - - // 이미지 처리 - savePostImages(imageFile, post); - Post createdPost = postRepository.save(post); - - return PostCreateResponse.from(createdPost); + try { + // 객체 생성 + Board board = boardRepository.getByCode(postCreateRequest.boardCode()); + Post post = postCreateRequest.toEntity(siteUser, board); + + // 이미지 처리 + savePostImages(imageFile, post); + Post createdPost = postRepository.save(post); + + return PostCreateResponse.from(createdPost); + } catch (Exception e) { + postRedisManager.releasePostCreationLock(siteUserId); + throw e; + }PostRedisManager에 다음 메서드를 추가하세요:🤖 Prompt for AI Agents