feat(nbstore): add indexer sync version (#11324)

This commit is contained in:
EYHN
2025-03-31 16:48:47 +00:00
parent d31e0c0e71
commit bc0f32f20b
5 changed files with 35 additions and 17 deletions
@@ -1,6 +1,8 @@
import { share } from '../../connection';
import type { DocClock } from '../../storage/doc';
import { IndexerSyncStorageBase } from '../../storage/indexer-sync';
import {
type DocIndexedClock,
IndexerSyncStorageBase,
} from '../../storage/indexer-sync';
import { IDBConnection, type IDBConnectionOptions } from './db';
export class IndexedDBIndexerSyncStorage extends IndexerSyncStorageBase {
@@ -12,21 +14,26 @@ export class IndexedDBIndexerSyncStorage extends IndexerSyncStorageBase {
super();
}
async getDocIndexedClock(docId: string): Promise<DocClock | null> {
async getDocIndexedClock(docId: string): Promise<DocIndexedClock | null> {
const tx = this.connection.inner.db.transaction('indexerSync', 'readonly');
const store = tx.store;
const result = await store.get(docId);
return result
? { docId: result.docId, timestamp: result.indexedClock }
? {
docId: result.docId,
timestamp: result.indexedClock,
indexerVersion: result.indexerVersion ?? 0,
}
: null;
}
async setDocIndexedClock(docClock: DocClock): Promise<void> {
async setDocIndexedClock(docClock: DocIndexedClock): Promise<void> {
const tx = this.connection.inner.db.transaction('indexerSync', 'readwrite');
const store = tx.store;
await store.put({
docId: docClock.docId,
indexedClock: docClock.timestamp,
indexerVersion: docClock.indexerVersion,
});
}
@@ -38,9 +38,9 @@ Table(PeerClocks)
| str | str | Date | Date |
Table(IndexerSync)
| docId | clock |
|-------|-------|
| str | Date |
| docId | indexedClock | indexerVersion |
|-------|--------------|----------------|
| str | Date | number |
Table(BlobSync)
| peer | key | uploadedAt |
@@ -134,6 +134,7 @@ export interface DocStorageSchema extends DBSchema {
value: {
docId: string;
indexedClock: Date;
indexerVersion?: number;
};
};
indexerMetadata: {