Skip to content

Commit ec56d6f

Browse files
committed
docs: 오타 수정
1 parent 589e3df commit ec56d6f

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

  • contents/posts/React/batch-api-atomic

contents/posts/React/batch-api-atomic/index.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ head:
3333

3434
## 기존 업로드 구조의 한계
3535

36-
기존 원아 등록 API 는 여러명의 데이터를 하나으 Multipart 요청으로 전송하는 구조였습니다.
36+
기존 원아 등록 API 는 여러명의 데이터를 하나의 Multipart 요청으로 전송하는 구조였습니다.
3737

3838
```bash
3939
POST /batch-upload
@@ -105,7 +105,7 @@ const compressedFile = await imageCompression(file, options);
105105

106106
<br/>
107107

108-
### 2️⃣ 요청청킹 + Batch 업로드
108+
### 2️⃣ 요청 청킹 + Batch 업로드
109109

110110
이미지 압축만으로는 한계가 있었기 때문에, 근본적으로 요청 자체를 여러 개로 나누는 방식을 도입했습니다.
111111

@@ -137,7 +137,7 @@ await Promise.all(chunks.map((chunk) => api.post("/batch-upload", chunk)));
137137

138138
> 중간에 일부 요청만 실패하면 어떻게 될까?
139139
140-
예를들어,
140+
예를 들어,
141141

142142
- 1~5명: 성공
143143
- 6~10명: 성공
@@ -146,7 +146,7 @@ await Promise.all(chunks.map((chunk) => api.post("/batch-upload", chunk)));
146146
이런 상황이 발생하면, 서버에는 이미 10명의 원아 데이터만 등록된 상태가 됩니다. <br>
147147
이는 흔히 말하는 원자성(Atomicity)을 깨는 구조입니다.
148148

149-
#### 1. 실패시 전체 롤백 (All or Nothing)
149+
#### 1. 실패 시 전체 롤백 (All or Nothing)
150150

151151
- 성공했던 요청까지 모두 삭제
152152
- DB 상태를 완전히 원래대로 복구
@@ -208,16 +208,16 @@ export class PartialSuccessError extends Error {
208208
```ts
209209
const results = await Promise.allSettled(requests);
210210

211-
const successIndices = results
212-
.map((result, index) => (result.status === "fulfilled" ? index : null))
213-
.filter((index) => index !== null);
211+
const successIndices = results.flatMap((result, index) =>
212+
result.status === "fulfilled" ? [index] : [],
213+
);
214214

215215
if (successIndices.length !== chunks.length) {
216216
throw new PartialSuccessError(successIndices);
217217
}
218218
```
219219

220-
이후, ReactHookForm 에서 이 에러를 잡아서 성공한 항목은 폼에서 제거하고, 실패한 항목만 그대로 남깁니다
220+
이후, React Hook Form 에서 이 에러를 잡아서 성공한 항목은 폼에서 제거하고, 실패한 항목만 그대로 남깁니다
221221

222222
```ts
223223
onError: (error) => {

0 commit comments

Comments
 (0)