From 8fd8e1766defcdc7d2e7237fc88900ae6f741e54 Mon Sep 17 00:00:00 2001 From: saeedjamshaid Date: Wed, 25 Mar 2026 13:05:52 +0500 Subject: [PATCH] fix: simplify portal serve caching logic and fix debounce scheduling (#252) What was changed? - Remove unnecessary mutex and event queue from portal serve action. - Fix debounce service to reschedule execution if a new handler arrived during processing. --- package-lock.json | 4 ++-- src/actions/portal/serve.ts | 18 ------------------ src/infrastructure/debounce-service.ts | 3 +++ 3 files changed, 5 insertions(+), 20 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8cd43ed6..e98fe599 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@apimatic/cli", - "version": "1.1.0-beta.8", + "version": "1.1.0-beta.9", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@apimatic/cli", - "version": "1.1.0-beta.8", + "version": "1.1.0-beta.9", "license": "MIT", "dependencies": { "@apimatic/sdk": "^0.2.0-alpha.7", diff --git a/src/actions/portal/serve.ts b/src/actions/portal/serve.ts index da9d98d5..d6ebdf54 100644 --- a/src/actions/portal/serve.ts +++ b/src/actions/portal/serve.ts @@ -2,8 +2,6 @@ import { createServer as createLiveReloadServer } from "livereload"; import connectLiveReload from "connect-livereload"; import express, { Express } from "express"; import chokidar from "chokidar"; -import crypto from "crypto"; -import { Mutex } from "async-mutex"; import { PortalServePrompts } from "../../prompts/portal/serve.js"; import { DirectoryPath } from "../../types/file/directoryPath.js"; import { ActionResult } from "../action-result.js"; @@ -86,10 +84,6 @@ export class PortalServeAction { }); const deletedDirectories = new Set(); - // TODO: Verify if we need mutex and eventQueue after refactoring. - const eventQueue = new Map(); - const mutex = new Mutex(); - const debounceService: DebounceService = new DebounceService(); watcher @@ -105,22 +99,10 @@ export class PortalServeAction { } } } - const eventId: string = `${Date.now()}-${crypto.randomUUID()}`; - await mutex.runExclusive(async () => { - eventQueue.clear(); - eventQueue.set(eventId, path); - }); await debounceService.batchSingleRequest(async () => { this.prompts.changesDetected(); - - // TODO: Verify if this is needed. - if (!eventQueue.has(eventId)) { - return; - } - await generatePortalAction.execute(buildDirectory, portalDirectory, true, false, false); - liveReloadServer.refresh(portalDirectory.toString()); this.clearStandardInput(); }); diff --git a/src/infrastructure/debounce-service.ts b/src/infrastructure/debounce-service.ts index 3f483771..65037d65 100644 --- a/src/infrastructure/debounce-service.ts +++ b/src/infrastructure/debounce-service.ts @@ -46,6 +46,9 @@ export class DebounceService { } } finally { this.isProcessing = false; + if (this.latestHandler) { + this.scheduleExecution(); + } } }, this.debounceMs); }