mirror of
https://github.com/stablyai/orca.git
synced 2026-10-23 16:03:49 +00:00
Follow-up to #2419: mark oversized filesystem watcher batches as overflow at enqueue time so the app does not retain thousands of paths before sending the conservative refresh.
39 lines
1.0 KiB
TypeScript
39 lines
1.0 KiB
TypeScript
import type { Event as WatcherEvent } from '@parcel/watcher'
|
|
|
|
export const MAX_BATCHED_WATCHER_EVENTS = 5_000
|
|
|
|
export type WatcherEventBatchState = {
|
|
events: WatcherEvent[]
|
|
overflowed: boolean
|
|
}
|
|
|
|
export function appendWatcherEvents(
|
|
batchEvents: WatcherEvent[],
|
|
incomingEvents: WatcherEvent[]
|
|
): void {
|
|
// Why: worktree deletion can deliver enough events that `push(...events)`
|
|
// exceeds V8's argument limit and crashes the main process.
|
|
for (const event of incomingEvents) {
|
|
batchEvents.push(event)
|
|
}
|
|
}
|
|
|
|
export function queueWatcherEvents(
|
|
batch: WatcherEventBatchState,
|
|
incomingEvents: WatcherEvent[]
|
|
): void {
|
|
if (batch.overflowed) {
|
|
return
|
|
}
|
|
|
|
if (batch.events.length + incomingEvents.length > MAX_BATCHED_WATCHER_EVENTS) {
|
|
// Why: once precision is too expensive, keeping every path only burns
|
|
// memory before flush sends the same conservative overflow refresh.
|
|
batch.events = []
|
|
batch.overflowed = true
|
|
return
|
|
}
|
|
|
|
appendWatcherEvents(batch.events, incomingEvents)
|
|
}
|