Implement code changes

The prompt asked to implement code changes.
This commit is contained in:
gpt-engineer-app[bot]
2025-03-18 07:49:51 +00:00
parent 8e609519ac
commit 612cd37b1d
11 changed files with 444 additions and 352 deletions

View File

@@ -3,23 +3,25 @@ import { supabase } from '@/lib/supabase';
import { isSyncEnabled } from '../syncSettings';
/**
* 간소화된 서버 트랜잭션 삭제 함수 - 안정성 최우선
* Supabase 서버에서 트랜잭션 삭제하는 함수 - 안정성 및 성능 최적화 버전
* 네트워크 타임아웃과 에러 처리를 강화하였습니다.
*/
export const deleteTransactionFromServer = async (userId: string, transactionId: string): Promise<void> => {
// 동기화 기능이 비활성화된 경우 빠르게 종료
if (!isSyncEnabled()) return;
try {
console.log(`[안정화] 서버 트랜잭션 삭제 요청: ${transactionId}`);
console.log(`[서버 삭제] 요청 시작: ${transactionId}`);
// 단축 타임아웃 (1.5초)
// 타임아웃 설정 (2초)
const controller = new AbortController();
const timeoutId = setTimeout(() => {
console.warn(`[안정화] 서버 삭제 타임아웃 (ID: ${transactionId})`);
console.warn(`[서버 삭제] 타임아웃 발생: ${transactionId}`);
controller.abort();
}, 1500);
}, 2000);
try {
// Supabase 요청에 AbortSignal 추가
// 서버 요청 실행
const { error } = await supabase
.from('transactions')
.delete()
@@ -27,26 +29,59 @@ export const deleteTransactionFromServer = async (userId: string, transactionId:
.eq('user_id', userId)
.abortSignal(controller.signal);
// 타임아웃
// 타임아웃 제
clearTimeout(timeoutId);
if (error) {
console.error('[안정화] 서버 삭제 실패:', error);
console.error('[서버 삭제] 실패:', error.message);
} else {
console.log(`[안정화] 서버 삭제 완료 (ID: ${transactionId})`);
console.log(`[서버 삭제] 성공: ${transactionId}`);
}
} catch (e) {
// 타임아웃 오류 처리
const error = e as Error & { code?: number };
if (error.name === 'AbortError' || error.code === 20) {
console.warn('[안정화] 서버 삭제 요청 타임아웃');
} else {
console.error('[안정화] 서버 삭제 오류:', error);
}
clearTimeout(timeoutId);
const error = e as Error;
if (error.name === 'AbortError') {
console.warn('[서버 삭제] 요청이 타임아웃으로 중단됨');
} else {
console.error('[서버 삭제] 오류 발생:', error);
}
}
} catch (error) {
console.error('[안정화] 서버 삭제 중 상위 오류:', error);
console.error('[서버 삭제] 예상치 못한 오류:', error);
}
};
/**
* 재시도 메커니즘이 포함된 트랜잭션 삭제 함수
* 최대 2회까지 재시도하며 네트워크 불안정 상황에서 안정성을 높입니다.
*/
export const deleteTransactionWithRetry = async (
userId: string,
transactionId: string,
maxRetries = 2
): Promise<boolean> => {
let retries = 0;
const attemptDelete = async (): Promise<boolean> => {
try {
await deleteTransactionFromServer(userId, transactionId);
return true;
} catch (error) {
if (retries < maxRetries) {
retries++;
console.log(`[서버 삭제] 재시도 ${retries}/${maxRetries}: ${transactionId}`);
// 지수 백오프 적용 (첫 재시도: 500ms, 두번째: 1000ms)
await new Promise(resolve => setTimeout(resolve, 500 * retries));
return attemptDelete();
} else {
console.warn(`[서버 삭제] 최대 재시도 횟수 초과: ${transactionId}`);
return false;
}
}
};
return attemptDelete();
};