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

Feature #21 '좋아요' 버튼 중 복 요청 문제 해결 #22

Merged
merged 6 commits into from
Dec 7, 2023

Conversation

j2h30728
Copy link
Owner

@j2h30728 j2h30728 commented Dec 6, 2023

Feature

  • 좋아요 버튼을 연속해서 눌렀을 때 좋아요가 여러 개 증가하는 문제 해결

Closes #21

Description

좋아요 버튼을 연속해서 눌렀을 때 좋아요가 여러 개 증가하는 문제

1. 사용자가 좋아요 버튼을 수없이 누를때 마다 api 요청이 계속되는 문제 해결

  • 버튼을 눌렀을때 UI만 변경시키는 낙관적업데이트는 동일하게 유지.
  • debounce 기능을 추가하여 좋아요를 연속으로 누를경우, 마지막 좋아요의 요청만을 서버로 보냄.
  • 좋아요 버튼을 누르고 난 뒤에는 revalidate를 실행 시키지 않음. :{ revalidate: false, rollbackOnError: true }

2. 연속적으로 들어가는 API 요청이 데이터 베이스에 중복해서 등록되는 문제 해결

  • 중복된 좋아요 처리를 위해 'tweetId_userId'복합키를 유니크 키로 생성.
  • 좋아요 API에서 트랜젝션과 유니크키를 사용하여 중복데이터를 체크하고 이미 데이터가 존재하면 에러를, 존재하지않으면 추가하는 방식으로 변경.

3. 좋아요 버튼을 명확하게 관리하기 위해 추가적인 작업

  • 이전에는 POST요청만 처리하는 좋아요 API를 별도의 POST/DELETE 요청으로 분리하여, 기능별 명확한 처리를 가능하게 함.

Reference

Copy link

codesandbox bot commented Dec 6, 2023

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

Copy link

vercel bot commented Dec 6, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
dam-witter ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 6, 2023 11:44pm

@j2h30728 j2h30728 merged commit d2e6839 into main Dec 7, 2023
3 checks passed
@j2h30728 j2h30728 deleted the feature-#21 branch December 7, 2023 00:03
@j2h30728 j2h30728 changed the title Feature #21 좋아요 버튼을 연속해서 눌렀을 때 좋아요가 여러 개 증가하는 문제 해결 Feature #21 '좋아요' 버튼 중 복 요청 문제 해결 Dec 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] 좋아요 버튼을 연속해서 눌렀을 때 좋아요가 여러 개 증가하는 문제
1 participant