Club
This commit is contained in:
parent
0e9703f770
commit
722cc74e64
1 changed files with 26 additions and 11 deletions
|
@ -561,23 +561,26 @@ class FolderWatcher {
|
|||
}
|
||||
}
|
||||
|
||||
// Batches all the files to be uploaded (or trashed) from the
|
||||
// event queue of same collection as the next event
|
||||
private clubSameCollectionEvents(): EventQueueItem {
|
||||
/**
|
||||
* Batch the next run of events with the same action, collection and folder
|
||||
* path into a single clubbed event that contains the list of all effected
|
||||
* file paths from the individual events.
|
||||
*/
|
||||
private dequeueClubbedEvent(): ClubbedWatchEvent | undefined {
|
||||
const event = this.eventQueue.shift();
|
||||
if (!event) return undefined;
|
||||
|
||||
const filePaths = [event.filePath];
|
||||
while (
|
||||
this.eventQueue.length > 0 &&
|
||||
event.collectionName === this.eventQueue[0].collectionName &&
|
||||
event.type === this.eventQueue[0].type
|
||||
event.action === this.eventQueue[0].action &&
|
||||
event.folderPath === this.eventQueue[0].folderPath &&
|
||||
event.collectionName === this.eventQueue[0].collectionName
|
||||
) {
|
||||
if (event.type === "trash") {
|
||||
event.paths = [...event.paths, ...this.eventQueue[0].paths];
|
||||
} else {
|
||||
event.files = [...event.files, ...this.eventQueue[0].files];
|
||||
}
|
||||
filePaths.push(this.eventQueue[0].filePath);
|
||||
this.eventQueue.shift();
|
||||
}
|
||||
return event;
|
||||
return { ...event, filePaths };
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -614,6 +617,18 @@ interface WatchEvent {
|
|||
filePath: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* A composite of multiple {@link WatchEvent}s that only differ in their
|
||||
* {@link filePath}.
|
||||
*
|
||||
* When processing events, we combine a run of events with the same
|
||||
* {@link action}, {@link folderPath} and {@link collectionName}. This allows us
|
||||
* to process all the affected {@link filePaths} in one shot.
|
||||
*/
|
||||
type ClubbedWatchEvent = Omit<WatchEvent, "filePath"> & {
|
||||
filePaths: string[];
|
||||
};
|
||||
|
||||
export function getValidFilesToUpload(
|
||||
files: ElectronFile[],
|
||||
mapping: FolderWatch,
|
||||
|
|
Loading…
Add table
Reference in a new issue