Skip to content

Fix #2467: [Bug]: File mirroring triggers multiple script executions - #2468

Open
GermanBluefox wants to merge 1 commit into
masterfrom
fix/issue-2467-mwpy88di
Open

GermanBluefox wants to merge 1 commit into
masterfrom
fix/issue-2467-mwpy88di

Conversation

@GermanBluefox

Copy link
Copy Markdown
Contributor

The mirror reacted to every single fs.watch event right away. Many editors save a file in several steps, so one save produced several "Update script … in DB" writes and several restarts of the script (#2467). Change and create events are now debounced per file (FILE_CHANGE_DEBOUNCE_MS, 300 ms). Only after that quiet time is the file read and handed to the existing logic, which now lives in _processFileChange(), so an unchanged source still leads to no update. Delete and rename events cancel a pending change first, and the new Mirror.destroy() clears pending timers and closes all folder and symlink watchers on adapter unload. Mocha tests check that several changes in a row lead to exactly one extendForeignObject call with the final content.

Fixes #2467

The mirror reacted to every single `fs.watch` event right away. Many editors save a file in several steps, so one save produced several "Update script … in DB" writes and several restarts of the script (#2467). Change and create events are now debounced per file (`FILE_CHANGE_DEBOUNCE_MS`, 300 ms). Only after that quiet time is the file read and handed to the existing logic, which now lives in `_processFileChange()`, so an unchanged source still leads to no update. Delete and rename events cancel a pending change first, and the new `Mirror.destroy()` clears pending timers and closes all folder and symlink watchers on adapter unload. Mocha tests check that several changes in a row lead to exactly one `extendForeignObject` call with the final content.

Fixes #2467
Comment thread src/lib/mirror.ts
}
try {
const stats = statSync(file);
const source = readFileSync(file).toString();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: File mirroring triggers multiple script executions

2 participants