From 7cfe8a1d69a2300facecb071a5352a5f60986a7a Mon Sep 17 00:00:00 2001 From: "andrew.ng" Date: Fri, 5 Jun 2026 09:50:13 +0700 Subject: [PATCH] Update lum la --- .claude/commands/ai-review.md | 10 +++------- BACKEND/app/controllers/logs_controller.ts | 4 ++-- BACKEND/app/services/line_connection.ts | 6 +++--- BACKEND/app/ultils/templates/show_inventory.ts | 2 +- FRONTEND/src/components/Drawer/DrawerLogs.tsx | 1 + 5 files changed, 10 insertions(+), 13 deletions(-) diff --git a/.claude/commands/ai-review.md b/.claude/commands/ai-review.md index 1fee51b..9b498d1 100644 --- a/.claude/commands/ai-review.md +++ b/.claude/commands/ai-review.md @@ -91,6 +91,7 @@ Soi các nguy cơ: - Redis state (`socket_state`, `station:{id}:line:{id}:history`): khi thêm field mới, `saveState` / `restoreState` có cover không. - Idle-timeout (`setTimeoutConnect`, 8h) **và** keep-alive (`keepConnectAPC` 40s / `keepConnectStation` 120s) có được wire đầy đủ cho connection mới không (theo CLAUDE.md). - Socket event mới: cả hai phía FE/BE có khớp tên + payload shape không. +- Ghi ngắn gọn nội dung #### 4.3. Performance @@ -99,13 +100,7 @@ Soi các nguy cơ: - Re-render React thừa (`App.tsx` đang dùng `lineBuffersRef` + flush 50ms — diff mới có phá vỡ pattern này không). - Bộ nhớ giữ output dài (truncate ở `saveState` 5000 chars — diff mới có giữ thêm field nặng không). - Setinterval/setTimeout có dồn (leak) không. - -#### 4.4. Consistency - -Hai gạch đầu dòng phụ: - -- **Đúng `CLAUDE.md`?** Đối chiếu từng quy ước liên quan: subpath imports `#controllers/*` (không phải relative trừ file ngoài `app/`), folder names `ultils`/`untils` (không rename), VN/EN comment language giữ nguyên, hot-reload boundaries, idle/keep-alive paired, `saveState`/`restoreState` extend khi thêm state. -- **Đúng coding standard?** ESLint flat config / Prettier / TS strict / naming convention (camelCase biến, PascalCase component, `T*` prefix cho type ở FE). Đặt tên file/component có nhất quán không. Comment có ý nghĩa, không lặp lại code. +- Ghi ngắn gọn nội dung #### 4.5. Simplicity @@ -113,6 +108,7 @@ Hai gạch đầu dòng phụ: - Có over-engineering, abstraction sớm. - Có thể gộp branch / sớm return để giảm nesting. - Đề xuất cụ thể cách rút gọn (mỗi đề xuất kèm trước/sau ngắn nếu hữu ích). +- Ghi ngắn gọn nội dung ### 5. Trả về kết quả diff --git a/BACKEND/app/controllers/logs_controller.ts b/BACKEND/app/controllers/logs_controller.ts index 099ba79..420a259 100644 --- a/BACKEND/app/controllers/logs_controller.ts +++ b/BACKEND/app/controllers/logs_controller.ts @@ -142,8 +142,8 @@ export default class LogsController { }) } - // Lấy 100 tên file đầu tiên từ danh sách lọc được - const result = files.slice(0, 100) + // Lấy 100 tên file mới nhất (cuối danh sách) + const result = files.slice(-100) return response.ok({ status: true, diff --git a/BACKEND/app/services/line_connection.ts b/BACKEND/app/services/line_connection.ts index ee827b1..19e9303 100644 --- a/BACKEND/app/services/line_connection.ts +++ b/BACKEND/app/services/line_connection.ts @@ -582,7 +582,7 @@ export default class LineConnection { ? { ...this.config.inventory, ...dataInventory, listInventory } : { ...dataInventory, listInventory } pid = dataInventory?.pid || '' - this.addHistory(this.config.stationId, this.config.id, { + await this.addHistory(this.config.stationId, this.config.id, { id: this.config.id, number: this.config.lineNumber, stationId: this.config.stationId, @@ -655,7 +655,7 @@ export default class LineConnection { }, data, }) - this.addHistory( + await this.addHistory( this.config.stationId, this.config.id, { @@ -2616,7 +2616,7 @@ Ports Missing/Down: ${missing.length}\n\n` console.error(`Failed to save report for SN ${reportSN}:`, err) } } - this.addHistory( + await this.addHistory( this.config.stationId, this.config.id, { diff --git a/BACKEND/app/ultils/templates/show_inventory.ts b/BACKEND/app/ultils/templates/show_inventory.ts index fce5ecc..cdd4a4a 100644 --- a/BACKEND/app/ultils/templates/show_inventory.ts +++ b/BACKEND/app/ultils/templates/show_inventory.ts @@ -37,7 +37,7 @@ const parseLog = (data: string) => { Object.keys(currentRecord).forEach((key) => { if (item && item[key] !== undefined) { if (key === "pid") { - item[key] = item[key].replace("(", '').replace(")", '') + item[key] = item[key].replace(/[()]/g, '') } currentRecord[key] = item[key].trim() } diff --git a/FRONTEND/src/components/Drawer/DrawerLogs.tsx b/FRONTEND/src/components/Drawer/DrawerLogs.tsx index 6321930..5e13b34 100644 --- a/FRONTEND/src/components/Drawer/DrawerLogs.tsx +++ b/FRONTEND/src/components/Drawer/DrawerLogs.tsx @@ -127,6 +127,7 @@ function DrawerLogs({ }, [testLogContent]); useEffect(() => { + if (!opened) return; // Clear previous debounce timer if (debounceTimerRef.current) { clearTimeout(debounceTimerRef.current);