From 5c2b3e9689bed2468cea485c765bda28ca9e9b40 Mon Sep 17 00:00:00 2001 From: harid Date: Mon, 11 May 2026 17:57:23 +0700 Subject: [PATCH] =?UTF-8?q?Clear=20Cache=20=E0=B8=AD=E0=B8=AD=E0=B8=81?= =?UTF-8?q?=E0=B8=84=E0=B8=B3=E0=B8=AA=E0=B8=B1=E0=B9=88=E0=B8=87=E0=B8=A3?= =?UTF-8?q?=E0=B8=B1=E0=B8=81=E0=B8=A9=E0=B8=B2=E0=B8=81=E0=B8=B2=E0=B8=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/CommandController.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index 232d2689..27d2671c 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -104,6 +104,10 @@ import { LeaveType } from "../entities/LeaveType"; import { KeycloakAttributeService } from "../services/KeycloakAttributeService"; import { reOrderCommandRecivesAndDelete } from "../services/CommandService"; import { RetirementService } from "../services/RetirementService"; +import { promisify } from "util"; +const REDIS_HOST = process.env.REDIS_HOST; +const REDIS_PORT = process.env.REDIS_PORT; + @Route("api/v1/org/command") @Tags("Command") @Security("bearerAuth") @@ -112,6 +116,7 @@ import { RetirementService } from "../services/RetirementService"; "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง", ) export class CommandController extends Controller { + private redis = require("redis"); private commandRepository = AppDataSource.getRepository(Command); private commandTypeRepository = AppDataSource.getRepository(CommandType); private commandSendRepository = AppDataSource.getRepository(CommandSend); @@ -7654,6 +7659,8 @@ export class CommandController extends Controller { throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบข้อมูล refIds"); } + const profileIdsToClearCache = new Set(); + await Promise.all( posMasters.map(async (item) => { // 4. ตรวจสอบข้อมูลที่จำเป็นทั้งหมด @@ -7662,6 +7669,10 @@ export class CommandController extends Controller { return; } + if (item.posMasterChild.current_holderId) { + profileIdsToClearCache.add(item.posMasterChild.current_holderId); + } + // 5. สร้าง orgShortName แบบปลอดภัย const orgShortName = [ @@ -7749,6 +7760,23 @@ export class CommandController extends Controller { }), ); + if (profileIdsToClearCache.size > 0) { + await Promise.all( + Array.from(profileIdsToClearCache).map(async (profileId) => { + const redisClient = await this.redis.createClient({ + host: REDIS_HOST, + port: REDIS_PORT, + }); + + const delAsync = promisify(redisClient.del).bind(redisClient); + await delAsync("role_" + profileId); + await delAsync("menu_" + profileId); + + redisClient.quit(); + }), + ); + } + return new HttpSuccess(); }