mirror of
https://github.com/stablyai/orca.git
synced 2026-11-17 03:15:01 +00:00
* perf(explorer): bound deferred filesystem watch events * test(explorer): drop duplicate watch buffer storm and GC retention tests --------- Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
42 lines
1.0 KiB
TypeScript
42 lines
1.0 KiB
TypeScript
import type { FsChangeEvent } from './filesystem-entry-types'
|
|
|
|
export const MAX_BUFFERED_FILE_WATCH_EVENTS = 5_000
|
|
|
|
export class FileWatchEventBuffer {
|
|
private events: FsChangeEvent[] = []
|
|
private overflowed = false
|
|
|
|
get size(): number {
|
|
return this.events.length
|
|
}
|
|
|
|
push(nextEvents: readonly FsChangeEvent[]): void {
|
|
if (nextEvents.length === 0 || this.overflowed) {
|
|
return
|
|
}
|
|
const incomingOverflow = nextEvents.find((event) => event.kind === 'overflow')
|
|
if (incomingOverflow) {
|
|
this.events = [incomingOverflow]
|
|
this.overflowed = true
|
|
} else if (this.events.length + nextEvents.length > MAX_BUFFERED_FILE_WATCH_EVENTS) {
|
|
this.events = [{ kind: 'overflow', absolutePath: nextEvents[0].absolutePath }]
|
|
this.overflowed = true
|
|
} else {
|
|
for (const event of nextEvents) {
|
|
this.events.push(event)
|
|
}
|
|
}
|
|
}
|
|
|
|
take(): FsChangeEvent[] {
|
|
const events = this.events
|
|
this.clear()
|
|
return events
|
|
}
|
|
|
|
clear(): void {
|
|
this.events = []
|
|
this.overflowed = false
|
|
}
|
|
}
|