mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-19 19:16:29 +08:00
feat(nbstore): add doc sync frontend (#9070)
This commit is contained in:
@@ -2,17 +2,37 @@ import type { DocStorage, SyncStorage } from '../../storage';
|
||||
import { DocSyncPeer } from './peer';
|
||||
|
||||
export class DocSyncEngine {
|
||||
private readonly peers: DocSyncPeer[];
|
||||
private abort: AbortController | null = null;
|
||||
|
||||
constructor(
|
||||
readonly local: DocStorage,
|
||||
readonly sync: SyncStorage,
|
||||
readonly peers: DocStorage[]
|
||||
) {}
|
||||
readonly remotes: DocStorage[]
|
||||
) {
|
||||
this.peers = remotes.map(remote => new DocSyncPeer(local, sync, remote));
|
||||
}
|
||||
|
||||
async run(signal?: AbortSignal) {
|
||||
await Promise.all(
|
||||
this.peers.map(peer =>
|
||||
new DocSyncPeer(this.local, this.sync, peer).mainLoop(signal)
|
||||
)
|
||||
);
|
||||
start() {
|
||||
if (this.abort) {
|
||||
this.abort.abort();
|
||||
}
|
||||
const abort = new AbortController();
|
||||
this.abort = abort;
|
||||
Promise.allSettled(
|
||||
this.peers.map(peer => peer.mainLoop(abort.signal))
|
||||
).catch(error => {
|
||||
console.error(error);
|
||||
});
|
||||
}
|
||||
|
||||
stop() {
|
||||
this.abort?.abort();
|
||||
this.abort = null;
|
||||
}
|
||||
|
||||
addPriority(id: string, priority: number) {
|
||||
const undo = this.peers.map(peer => peer.addPriority(id, priority));
|
||||
return () => undo.forEach(fn => fn());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -610,11 +610,6 @@ export class DocSyncPeer {
|
||||
this.statusUpdatedSubject$.next(job.docId);
|
||||
}
|
||||
|
||||
setPriority(docId: string, priority: number) {
|
||||
this.prioritySettings.set(docId, priority);
|
||||
return this.status.jobDocQueue.setPriority(docId, priority);
|
||||
}
|
||||
|
||||
addPriority(id: string, priority: number) {
|
||||
const oldPriority = this.prioritySettings.get(id) ?? 0;
|
||||
this.prioritySettings.set(id, priority);
|
||||
|
||||
Reference in New Issue
Block a user