fix(nbstore): connect before do operation (#11569)

This commit is contained in:
EYHN
2025-04-10 16:05:46 +08:00
committed by GitHub
parent 3629a725d2
commit a759a1988e
9 changed files with 150 additions and 104 deletions
+2 -1
View File
@@ -1,3 +1,4 @@
import { share } from '../../connection';
import {
type DocClock,
type DocClocks,
@@ -17,7 +18,7 @@ interface ChannelMessage {
export class IndexedDBDocStorage extends DocStorageBase<IDBConnectionOptions> {
static readonly identifier = 'IndexedDBDocStorage';
readonly connection = new IDBConnection(this.options);
readonly connection = share(new IDBConnection(this.options));
get db() {
return this.connection.inner.db;
@@ -1,5 +1,6 @@
import { merge, Observable, of, Subject, throttleTime } from 'rxjs';
import { share } from '../../../connection';
import type {
AggregateOptions,
AggregateResult,
@@ -10,13 +11,14 @@ import type {
SearchResult,
} from '../../../storage';
import { IndexerStorageBase } from '../../../storage';
import { fromPromise } from '../../../utils/from-promise';
import { IDBConnection, type IDBConnectionOptions } from '../db';
import { DataStruct } from './data-struct';
import { backoffRetry, exhaustMapWithTrailing, fromPromise } from './utils';
import { backoffRetry, exhaustMapWithTrailing } from './utils';
export class IndexedDBIndexerStorage extends IndexerStorageBase {
static readonly identifier = 'IndexedDBIndexerStorage';
readonly connection = new IDBConnection(this.options);
readonly connection = share(new IDBConnection(this.options));
override isReadonly = false;
private readonly data = new DataStruct();
private readonly tableUpdate$ = new Subject<string>();
@@ -3,7 +3,7 @@ import {
defer,
exhaustMap,
finalize,
Observable,
type Observable,
type ObservableInput,
type OperatorFunction,
retry,
@@ -14,8 +14,6 @@ import {
timer,
} from 'rxjs';
import { MANUALLY_STOP } from '../../../utils/throw-if-aborted';
/**
* Like exhaustMap, but also includes the trailing value emitted from the source observable while waiting for the preceding inner observable to complete
*
@@ -45,33 +43,6 @@ export function exhaustMapWithTrailing<T, R>(
});
}
/**
* Convert a promise to an observable.
*
* like `from` but support `AbortSignal`.
*/
export function fromPromise<T>(
promise: Promise<T> | ((signal: AbortSignal) => Promise<T>)
): Observable<T> {
return new Observable(subscriber => {
const abortController = new AbortController();
const rawPromise =
promise instanceof Function ? promise(abortController.signal) : promise;
rawPromise
.then(value => {
subscriber.next(value);
subscriber.complete();
})
.catch(error => {
subscriber.error(error);
});
return () => abortController.abort(MANUALLY_STOP);
});
}
/**
* An operator that retries the source observable when an error occurs.
*