diff options
| author | joonhoekim <26rote@gmail.com> | 2025-10-27 10:54:48 +0900 |
|---|---|---|
| committer | joonhoekim <26rote@gmail.com> | 2025-10-27 10:54:48 +0900 |
| commit | 92766c1f2096852e7f224629963a412af8a16586 (patch) | |
| tree | e79600d6df56fce1a84fe8a76d69339e5d1a85c4 /lib/swp/actions.ts | |
| parent | 65a68325658401dd8a90ea900c1542c17c63d7ce (diff) | |
(김준회) SWP 코드추출 리팩터링, 파일수 조회 쿼리 통일, 헬프다이얼로그 문구 개선
Diffstat (limited to 'lib/swp/actions.ts')
| -rw-r--r-- | lib/swp/actions.ts | 21 |
1 files changed, 14 insertions, 7 deletions
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<number>`COUNT(DISTINCT ${swpDocumentRevisions.id})::int`, - file_count: sql<number>`COUNT(${swpDocumentFiles.id})::int`, + file_count: sql<number>`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<number>`( - SELECT COUNT(*)::int - FROM swp.swp_document_files f - WHERE f.revision_id = ${swpDocumentRevisions.id} - )`, + file_count: sql<number>`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<number>`COUNT(DISTINCT ${swpDocuments.DOC_NO})::int`, total_revisions: sql<number>`COUNT(DISTINCT ${swpDocumentRevisions.id})::int`, - total_files: sql<number>`COUNT(${swpDocumentFiles.id})::int`, + total_files: sql<number>`COUNT(DISTINCT ${swpDocumentFiles.id})::int`, last_sync: sql<Date>`MAX(${swpDocuments.last_synced_at})`, }) .from(swpDocuments) |
