Skip to content

Commit 6c28da7

Browse files
fix: simplify portal serve caching logic and fix debounce scheduling (#253)
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. Co-authored-by: saeedjamshaid <saeed.jamshaid@outlook.com>
1 parent da7e591 commit 6c28da7

3 files changed

Lines changed: 5 additions & 20 deletions

File tree

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/actions/portal/serve.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import { createServer as createLiveReloadServer } from "livereload";
22
import connectLiveReload from "connect-livereload";
33
import express, { Express } from "express";
44
import chokidar from "chokidar";
5-
import crypto from "crypto";
6-
import { Mutex } from "async-mutex";
75
import { PortalServePrompts } from "../../prompts/portal/serve.js";
86
import { DirectoryPath } from "../../types/file/directoryPath.js";
97
import { ActionResult } from "../action-result.js";
@@ -86,10 +84,6 @@ export class PortalServeAction {
8684
});
8785

8886
const deletedDirectories = new Set<string>();
89-
// TODO: Verify if we need mutex and eventQueue after refactoring.
90-
const eventQueue = new Map();
91-
const mutex = new Mutex();
92-
9387
const debounceService: DebounceService = new DebounceService();
9488

9589
watcher
@@ -105,22 +99,10 @@ export class PortalServeAction {
10599
}
106100
}
107101
}
108-
const eventId: string = `${Date.now()}-${crypto.randomUUID()}`;
109-
await mutex.runExclusive(async () => {
110-
eventQueue.clear();
111-
eventQueue.set(eventId, path);
112-
});
113102

114103
await debounceService.batchSingleRequest(async () => {
115104
this.prompts.changesDetected();
116-
117-
// TODO: Verify if this is needed.
118-
if (!eventQueue.has(eventId)) {
119-
return;
120-
}
121-
122105
await generatePortalAction.execute(buildDirectory, portalDirectory, true, false, false);
123-
124106
liveReloadServer.refresh(portalDirectory.toString());
125107
this.clearStandardInput();
126108
});

src/infrastructure/debounce-service.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ export class DebounceService {
4646
}
4747
} finally {
4848
this.isProcessing = false;
49+
if (this.latestHandler) {
50+
this.scheduleExecution();
51+
}
4952
}
5053
}, this.debounceMs);
5154
}

0 commit comments

Comments
 (0)