mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-20 03:26:47 +08:00
feat(nbstore): add indexer sync version (#11324)
This commit is contained in:
@@ -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: {
|
||||
|
||||
Reference in New Issue
Block a user