Refactor project for improvements

This commit refactors the project to improve overall code quality, performance, and maintainability. Specific changes may include code cleanup, optimization, and architectural enhancements.
This commit is contained in:
gpt-engineer-app[bot]
2025-03-18 07:45:06 +00:00
parent 854d27574f
commit 8e609519ac
4 changed files with 109 additions and 104 deletions

View File

@@ -1,10 +1,9 @@
import { supabase } from '@/lib/supabase';
import { isSyncEnabled } from '../syncSettings';
import { toast } from '@/hooks/useToast.wrapper';
/**
* 특정 트랜잭션 ID 삭제 처리 - Lovable 환경 최적화 버전
* 간소화된 서버 트랜잭션 삭제 함수 - 안정성 최우선
*/
export const deleteTransactionFromServer = async (userId: string, transactionId: string): Promise<void> => {
if (!isSyncEnabled()) return;
@@ -12,12 +11,12 @@ export const deleteTransactionFromServer = async (userId: string, transactionId:
try {
console.log(`[안정화] 서버 트랜잭션 삭제 요청: ${transactionId}`);
// 단축 타임아웃 (2초)
// 단축 타임아웃 (1.5초)
const controller = new AbortController();
const timeoutId = setTimeout(() => {
console.warn(`[안정화] 서버 트랜잭션 삭제 타임아웃 (ID: ${transactionId})`);
console.warn(`[안정화] 서버 삭제 타임아웃 (ID: ${transactionId})`);
controller.abort();
}, 2000);
}, 1500);
try {
// Supabase 요청에 AbortSignal 추가
@@ -28,31 +27,26 @@ export const deleteTransactionFromServer = async (userId: string, transactionId:
.eq('user_id', userId)
.abortSignal(controller.signal);
// 요청 완료 후 타임아웃 해제
// 타임아웃 해제
clearTimeout(timeoutId);
if (error) {
console.error('[안정화] 서버 트랜잭션 삭제 실패:', error);
return; // 오류 있어도 계속 진행
console.error('[안정화] 서버 삭제 실패:', error);
} 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(`[안정화] 서버 트랜잭션 삭제 요청 타임아웃 (ID: ${transactionId})`);
return; // 정상적으로 처리된 것으로 간주
console.warn('[안정화] 서버 삭제 요청 타임아웃');
} else {
console.error('[안정화] 서버 삭제 오류:', error);
}
console.error('[안정화] 서버 삭제 중 오류 (무시):', error);
} finally {
clearTimeout(timeoutId); // 안전하게 항상 타임아웃 해제
clearTimeout(timeoutId);
}
} catch (error) {
console.error('[안정화] 서버 트랜잭션 삭제 중 상위 오류:', error);
// UI 차단하지 않음 (로컬 데이터 우선)
console.log('[안정화] 서버 동기화 오류 발생했으나 UI 작업은 계속 진행됨');
console.error('[안정화] 서버 삭제 중 상위 오류:', error);
}
};