refactor: fix security hardcode, dead code, resource leaks, operator bugs

This commit is contained in:
2026-05-06 12:31:58 +09:00
parent 0c9def0241
commit 17e6503ccd
8 changed files with 134 additions and 59 deletions
+9 -28
View File
@@ -1,5 +1,5 @@
/**
* 집계 결과 타입 정의
* Aggregate result type definition
*/
export interface AggregateResult {
key: string;
@@ -14,14 +14,14 @@ interface AggregateOptions {
/**
* DataProcessor:
* 시스템의 알고리즘적 효율성과 유지보수성을 극대화하기 위한 핵심 집계 엔진.
* O(N) 복잡도를 보장하며 데이터 분포 민감도를 고려한 최적화 전략을 포함합니다.
* Core aggregation engine for maximizing algorithmic efficiency and maintainability.
* Guarantees O(N) complexity with data distribution-sensitive optimization strategy.
*/
export class DataProcessor {
/**
* 핵심 데이터 집계 함수 (Optimized O(N))
* @param data 집계할 데이터 배열
* @param keyPath 집계 기준이 될 속성 경로
* Core data aggregation function (Optimized O(N))
* @param data Array to aggregate
* @param keyPath Property path to group by
*/
public static aggregate(data: any[], keyPath: string, options: AggregateOptions = {}): AggregateResult[] {
if (!data || data.length === 0) return [];
@@ -31,10 +31,6 @@ export class DataProcessor {
const pathSegments = this.parseKeyPath(keyPath);
const collectValues = options.collectValues !== false;
// 1. 성능 상충 관계 (Sweet Spot) 고려:
// 데이터가 매우 작을 때는(예: N < 10) 해시 맵 생성 오버헤드가 더 클 수 있으나,
// 일반적인 성능 보장을 위해 해시 기반 단일 패스(Single-Pass) 방식을 기본으로 채택합니다.
const map = new Map<string, AggregateResult>();
@@ -59,15 +55,9 @@ export class DataProcessor {
if (collectValues) {
entry.values.push(item);
}
// 수치형 데이터인 경우 평균 계산을 위한 로직 (예시)
if (typeof item.value === 'number') {
// 점진적 평균 계산 등 추가 가능
}
} catch (error) {
// 오류 처리 정밀도 (Error Handling Granularity)
// 특정 아이템 처리 실패가 전체 집계 중단으로 이어지지 않도록 격리
// Isolate item processing failures to prevent entire aggregation from aborting
console.warn(`[DataProcessor] Skip item due to error: ${error}`);
}
}
@@ -76,17 +66,8 @@ export class DataProcessor {
}
/**
* 데이터 분포 민감성(Data Distribution Sensitivity)을 고려한 고도화된 집계 (Trie 기반)
* 키가 매우 길거나 계층적인 경우 메모리 및 검색 속도 최적화를 위해 사용합니다.
*/
public static aggregateByTrie(data: any[], keyPath: string, options: AggregateOptions = {}): AggregateResult[] {
// TODO: 복잡한 키 구조를 위한 Trie 인덱싱 로직 구현 (Phase 2 확장 예정)
return this.aggregate(data, keyPath, options);
}
/**
* 중첩된 객체 속성 접근 (Safety handling).
* keyPath는 루프 밖에서 한 번만 파싱하여 대규모 데이터 처리 시 반복 split 비용을 피합니다.
* Nested object property accessor (safety handling).
* keyPath is parsed once outside the loop to avoid repeated split costs on large datasets.
*/
private static getNestedValue(obj: any, pathSegments: string[]): any {
return pathSegments.reduce((prev, curr) => {