feat(core): run indexer in worker (#7418)

This commit is contained in:
liuyi
2024-07-04 15:37:26 +08:00
committed by GitHub
parent 5c1f78afd4
commit 555f203be6
15 changed files with 717 additions and 362 deletions

View File

@@ -18,6 +18,7 @@ import {
timer,
} from 'rxjs';
import { MANUALLY_STOP } from '../utils';
import type { LiveData } from './livedata';
/**
@@ -107,7 +108,8 @@ export function fromPromise<T>(
.catch(error => {
subscriber.error(error);
});
return () => abortController.abort('Aborted');
return () => abortController.abort(MANUALLY_STOP);
});
}

View File

@@ -4,6 +4,7 @@ import { difference } from 'lodash-es';
import { LiveData } from '../../livedata';
import type { Memento } from '../../storage';
import { MANUALLY_STOP } from '../../utils';
import { BlobStorageOverCapacity } from './error';
const logger = new DebugLogger('affine:blob-engine');
@@ -70,7 +71,7 @@ export class BlobEngine {
}
stop() {
this.abort?.abort();
this.abort?.abort(MANUALLY_STOP);
this.abort = null;
}

View File

@@ -0,0 +1,24 @@
AFFiNE currently has a lot of data stored using the old ID format. Here, we record the usage of IDs to avoid forgetting.
## Old ID Format
The format is:
- `{workspace-id}:space:{nanoid}` Common
- `{workspace-id}:space:page:{nanoid}`
> Note: sometimes the `workspace-id` is not same with current workspace id.
## Usage
- Local Storage
- indexeddb: Both new and old IDs coexist
- sqlite: Both new and old IDs coexist
- server-clock: Only new IDs are stored
- sync-metadata: Both new and old IDs coexist
- Server Storage
- Only stores new IDs but accepts writes using old IDs
- Protocols
- When the client submits an update, both new and old IDs are used.
- When the server broadcasts updates sent by other clients, both new and old IDs are used.
- When the server responds to `client-pre-sync` (listing all updated docids), only new IDs are used.

View File

@@ -20,6 +20,9 @@ export interface IndexWriter<S extends Schema>
delete(id: string): void;
// TODO(@eyhn)
// deleteByQuery(query: Query<S>): void;
commit(): Promise<void>;
rollback(): void;

View File

@@ -155,6 +155,9 @@ export class IndexedDBJobQueue<J> implements JobQueue<J> {
.objectStore('jobs')
.delete(typeof id === 'string' ? parseInt(id) : id);
}
trx.commit();
this.broadcast.postMessage('job-completed');
}
async return(jobs: Job[], retry: boolean = false): Promise<void> {
@@ -174,6 +177,10 @@ export class IndexedDBJobQueue<J> implements JobQueue<J> {
.delete(typeof id === 'string' ? parseInt(id) : id);
}
}
trx.commit();
this.broadcast.postMessage('job-completed');
}
async clear(): Promise<void> {

View File

@@ -29,7 +29,7 @@ export class JobRunner<J> {
}
stop() {
this.abort?.abort();
this.abort?.abort(MANUALLY_STOP);
this.abort = null;
}