feat: refresh index if version changed (#14150)

This commit is contained in:
DarkSky
2025-12-26 01:08:05 +08:00
committed by GitHub
parent e8693a3a25
commit 2e38898937
19 changed files with 57 additions and 19 deletions
@@ -106,10 +106,6 @@ export interface IndexerSync {
}
export class IndexerSyncImpl implements IndexerSync {
/**
* increase this number to re-index all docs
*/
readonly INDEXER_VERSION = 2;
private abort: AbortController | null = null;
private readonly rootDocId = this.doc.spaceId;
private readonly status = new IndexerSyncStatus(this.rootDocId);
@@ -266,7 +262,8 @@ export class IndexerSyncImpl implements IndexerSync {
this.status.errorMessage = null;
this.status.statusUpdatedSubject$.next(true);
console.log('indexer sync start');
const indexVersion = await this.indexer.indexVersion();
console.log('indexer sync start, version: ', indexVersion);
const unsubscribe = this.doc.subscribeDocUpdate(update => {
if (!this.status.rootDocReady) {
@@ -402,7 +399,7 @@ export class IndexerSyncImpl implements IndexerSync {
docIndexedClock &&
docIndexedClock.timestamp.getTime() ===
docClock.timestamp.getTime() &&
docIndexedClock.indexerVersion === this.INDEXER_VERSION
docIndexedClock.indexerVersion === indexVersion
) {
// doc is already indexed, just skip
continue;
@@ -468,7 +465,7 @@ export class IndexerSyncImpl implements IndexerSync {
await this.indexerSync.setDocIndexedClock({
docId,
timestamp: docClock.timestamp,
indexerVersion: this.INDEXER_VERSION,
indexerVersion: indexVersion,
});
// #endregion
}