From 92766c1f2096852e7f224629963a412af8a16586 Mon Sep 17 00:00:00 2001 From: joonhoekim <26rote@gmail.com> Date: Mon, 27 Oct 2025 10:54:48 +0900 Subject: (김준회) SWP 코드추출 리팩터링, 파일수 조회 쿼리 통일, 헬프다이얼로그 문구 개선 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/swp/actions.ts | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'lib/swp/actions.ts') diff --git a/lib/swp/actions.ts b/lib/swp/actions.ts index 7411f414..f58793e2 100644 --- a/lib/swp/actions.ts +++ b/lib/swp/actions.ts @@ -110,7 +110,7 @@ export async function fetchSwpDocuments(params: SwpTableParams) { sync_status: swpDocuments.sync_status, last_synced_at: swpDocuments.last_synced_at, revision_count: sql`COUNT(DISTINCT ${swpDocumentRevisions.id})::int`, - file_count: sql`COUNT(${swpDocumentFiles.id})::int`, + file_count: sql`COUNT(DISTINCT ${swpDocumentFiles.id})::int`, }) .from(swpDocuments) .leftJoin(swpDocumentRevisions, eq(swpDocuments.DOC_NO, swpDocumentRevisions.DOC_NO)) @@ -162,14 +162,21 @@ export async function fetchDocumentRevisions(docNo: string) { OFDC_NO: swpDocumentRevisions.OFDC_NO, sync_status: swpDocumentRevisions.sync_status, last_synced_at: swpDocumentRevisions.last_synced_at, - file_count: sql`( - SELECT COUNT(*)::int - FROM swp.swp_document_files f - WHERE f.revision_id = ${swpDocumentRevisions.id} - )`, + file_count: sql`COUNT(DISTINCT ${swpDocumentFiles.id})::int`, }) .from(swpDocumentRevisions) + .leftJoin(swpDocumentFiles, eq(swpDocumentRevisions.id, swpDocumentFiles.revision_id)) .where(eq(swpDocumentRevisions.DOC_NO, docNo)) + .groupBy( + swpDocumentRevisions.id, + swpDocumentRevisions.DOC_NO, + swpDocumentRevisions.REV_NO, + swpDocumentRevisions.STAGE, + swpDocumentRevisions.ACTV_NO, + swpDocumentRevisions.OFDC_NO, + swpDocumentRevisions.sync_status, + swpDocumentRevisions.last_synced_at + ) .orderBy(desc(swpDocumentRevisions.REV_NO)); return revisions; @@ -268,7 +275,7 @@ export async function fetchSwpStats(projNo?: string) { .select({ total_documents: sql`COUNT(DISTINCT ${swpDocuments.DOC_NO})::int`, total_revisions: sql`COUNT(DISTINCT ${swpDocumentRevisions.id})::int`, - total_files: sql`COUNT(${swpDocumentFiles.id})::int`, + total_files: sql`COUNT(DISTINCT ${swpDocumentFiles.id})::int`, last_sync: sql`MAX(${swpDocuments.last_synced_at})`, }) .from(swpDocuments) -- cgit v1.2.3