summaryrefslogtreecommitdiff
path: root/lib/sedp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sedp')
-rw-r--r--lib/sedp/sync-form.ts40
1 files changed, 28 insertions, 12 deletions
diff --git a/lib/sedp/sync-form.ts b/lib/sedp/sync-form.ts
index e3c3f6bb..904d27ba 100644
--- a/lib/sedp/sync-form.ts
+++ b/lib/sedp/sync-form.ts
@@ -913,8 +913,8 @@ async function getContractItemsByItemCodes(itemCodes: string[], projectId: numbe
export async function saveFormMappingsAndMetas(
projectId: number,
projectCode: string,
- registers: Register[], // legacy SEDP Register list (supplemental)
- newRegisters: newRegister[] // AdapterDataMapping list (primary)
+ registers: Register[],
+ newRegisters: newRegister[]
): Promise<number> {
try {
/* ------------------------------------------------------------------ */
@@ -929,14 +929,17 @@ export async function saveFormMappingsAndMetas(
const registerMap = new Map(registers.map(r => [r.TYPE_ID, r]));
const attributeMap = await getAttributes(projectCode);
- const codeListMap = await getCodeLists(projectCode);
+ // getCodeLists 호출 제거
+ // const codeListMap = await getCodeLists(projectCode);
const uomMap = await getUOMs(projectCode);
const defaultAttributes = await getDefaulTAttributes();
+ // 성능 향상을 위한 코드 리스트 캐시 추가 (선택사항)
+ const codeListCache = new Map<string, CodeList | null>();
+
/* ------------------------------------------------------------------ */
- /* 2. Contract‑item look‑up (SCOPES) - 수정된 부분 */
+ /* 2. Contract‑item look‑up (SCOPES) */
/* ------------------------------------------------------------------ */
- // SCOPES 배열에서 모든 unique한 itemCode들을 추출
const uniqueItemCodes = [...new Set(
newRegisters
.filter(nr => nr.SCOPES && nr.SCOPES.length > 0)
@@ -1002,9 +1005,26 @@ export async function saveFormMappingsAndMetas(
...(uomSymbol ? { uom: uomSymbol, uomId } : {})
};
+ // 수정된 부분: getCodeListById 사용
if (!defaultAttributes.includes(attId) && (attribute.VAL_TYPE === "LIST" || attribute.VAL_TYPE === "DYNAMICLIST") && attribute.CL_ID) {
- const cl = codeListMap.get(attribute.CL_ID);
- if (cl?.VALUES?.length) col.options = [...new Set(cl.VALUES.filter(v => v.USE_YN).map(v => v.VALUE))];
+ // 캐시 확인
+ let cl = codeListCache.get(attribute.CL_ID);
+
+ // 캐시에 없으면 API 호출
+ if (!codeListCache.has(attribute.CL_ID)) {
+ try {
+ cl = await getCodeListById(projectCode, attribute.CL_ID);
+ codeListCache.set(attribute.CL_ID, cl); // 캐시에 저장
+ } catch (error) {
+ console.warn(`코드 리스트 ${attribute.CL_ID} 가져오기 실패:`, error);
+ cl = null;
+ codeListCache.set(attribute.CL_ID, null); // 실패도 캐시에 저장
+ }
+ }
+
+ if (cl?.VALUES?.length) {
+ col.options = [...new Set(cl.VALUES.filter(v => v.USE_YN).map(v => v.VALUE))];
+ }
}
columns.push(col);
@@ -1025,7 +1045,6 @@ export async function saveFormMappingsAndMetas(
if (!cls) { console.warn(`클래스 ${classId} 없음`); return; }
const tp = tagTypeMap.get(cls.tagTypeCode);
if (!tp) { console.warn(`태그 타입 ${cls.tagTypeCode} 없음`); return; }
- // SCOPES 배열을 문자열로 변환하여 remark에 저장
const scopesRemark = newReg.SCOPES && newReg.SCOPES.length > 0 ? newReg.SCOPES.join(', ') : null;
mappingsToSave.push({
projectId,
@@ -1040,13 +1059,11 @@ export async function saveFormMappingsAndMetas(
});
});
- /* ---------- 4‑d. contractItem ↔ form - 수정된 부분 -------------- */
+ /* ---------- 4‑d. contractItem ↔ form -------------------------- */
if (newReg.SCOPES && newReg.SCOPES.length > 0) {
- // SCOPES 배열의 각 itemCode에 대해 처리
for (const itemCode of newReg.SCOPES) {
const contractItemIds = itemCodeToContractItemIds.get(itemCode);
if (contractItemIds && contractItemIds.length > 0) {
- // 모든 contractItemId에 대해 form 생성
contractItemIds.forEach(cId => {
contractItemIdsWithForms.add(cId);
formsToSave.push({
@@ -1096,7 +1113,6 @@ export async function saveFormMappingsAndMetas(
}
}
-
// 메인 동기화 함수
export async function syncTagFormMappings() {
try {