Skip to content

Refactor watcher 2#1316

Open
dajimenezriv-internxt wants to merge 25 commits intomainfrom
refactor-watcher-2
Open

Refactor watcher 2#1316
dajimenezriv-internxt wants to merge 25 commits intomainfrom
refactor-watcher-2

Conversation

@dajimenezriv-internxt
Copy link
Contributor

@dajimenezriv-internxt dajimenezriv-internxt commented Mar 23, 2026

What

Refactor the watcher in C++. Now we are going to obtain the extended information from windows, which includes an internalId, size, mtime and ctime. We are going to send all events to javascript and there we are going to log them and group by internalId. The timeout to group is 2s. After that, if we are 2s without having any new event of an internalId we process that last event received with that internalId. This improve the issue of the move operation (it sends a delete event and after that a create event) and also the one of locked files (it sends a create event with size 0 and then many update events with size X until it reaches the final size Y). This second case it's more tricky to test since I don't know how much time can we expect from one update to another. I've added a test for that but probably we will need to continue improving this part.

@dajimenezriv-internxt dajimenezriv-internxt self-assigned this Mar 23, 2026
const events = new Map<number, { event: Watcher.SuccessEvent; timer: NodeJS.Timeout }>();
const DEBOUNCE_MS = process.env.NODE_ENV === 'test' ? 50 : 2000;

function onEvent({ ctx, event }: { ctx: SyncContext; event: Watcher.Event }) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the main change of this PR.

await sleep(100);
await checkIfModified(props);
await sleep(100);
return;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We fix this in the next PR.

// When
await writeFile(file, 'content');
await sleep(3000);
return;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We fix this in the next PR.

timeout = setTimeout(async () => {
timeouts.delete(path);
await onChange({ ctx, path });
await onChange({ ctx, path } as any);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file will be deleted in the next PR.

Base automatically changed from refactor-watcher to main March 24, 2026 15:28
@sonarqubecloud
Copy link

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.

1 participant