mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 13:25:12 +00:00
fix(nbstore): fix v1 doc storage timestamp (#10282)
This commit is contained in:
@@ -17,6 +17,13 @@ import {
|
||||
import { getIdConverter } from '../../../utils/id-converter';
|
||||
import { DocIDBConnection } from './db';
|
||||
|
||||
/**
|
||||
* We use a fixed timestamp in v1 because the v1 should never be changed.
|
||||
* This date is chosen because it is large enough to overwrite some previous error data.
|
||||
* In our sync storage, only a larger timestamp can overwrite smaller one.
|
||||
*/
|
||||
const CONST_TIMESTAMP = new Date(1893456000000);
|
||||
|
||||
/**
|
||||
* @deprecated readonly
|
||||
*/
|
||||
@@ -45,7 +52,14 @@ export class IndexedDBV1DocStorage extends DocStorageBase {
|
||||
return null;
|
||||
}
|
||||
const oldId = (await this.getIdConverter()).newIdToOldId(docId);
|
||||
return this.rawGetDoc(oldId);
|
||||
const rawDoc = await this.rawGetDoc(oldId);
|
||||
return rawDoc
|
||||
? {
|
||||
docId: rawDoc.docId,
|
||||
bin: rawDoc.bin,
|
||||
timestamp: CONST_TIMESTAMP,
|
||||
}
|
||||
: null;
|
||||
}
|
||||
|
||||
protected override async getDocSnapshot() {
|
||||
@@ -54,7 +68,7 @@ export class IndexedDBV1DocStorage extends DocStorageBase {
|
||||
|
||||
override async pushDocUpdate(update: DocUpdate) {
|
||||
// no more writes to old db
|
||||
return { docId: update.docId, timestamp: new Date() };
|
||||
return { docId: update.docId, timestamp: CONST_TIMESTAMP };
|
||||
}
|
||||
|
||||
override async deleteDoc(docId: string) {
|
||||
@@ -110,7 +124,7 @@ export class IndexedDBV1DocStorage extends DocStorageBase {
|
||||
);
|
||||
|
||||
return Object.fromEntries(
|
||||
oldIds.map(id => [idConverter.oldIdToNewId(id), new Date(1)])
|
||||
oldIds.map(id => [idConverter.oldIdToNewId(id), CONST_TIMESTAMP])
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,13 @@ import { isEmptyUpdate } from '../../../utils/is-empty-update';
|
||||
import type { SpaceType } from '../../../utils/universal-id';
|
||||
import { apis } from './db';
|
||||
|
||||
/**
|
||||
* We use a fixed timestamp in v1 because the v1 should never be changed.
|
||||
* This date is chosen because it is large enough to overwrite some previous error data.
|
||||
* In our sync storage, only a larger timestamp can overwrite smaller one.
|
||||
*/
|
||||
const CONST_TIMESTAMP = new Date(1893456000000);
|
||||
|
||||
/**
|
||||
* @deprecated readonly
|
||||
*/
|
||||
@@ -34,7 +41,7 @@ export class SqliteV1DocStorage extends DocStorageBase<{
|
||||
|
||||
override async pushDocUpdate(update: DocUpdate) {
|
||||
// no more writes
|
||||
return { docId: update.docId, timestamp: new Date() };
|
||||
return { docId: update.docId, timestamp: CONST_TIMESTAMP };
|
||||
}
|
||||
|
||||
override async getDoc(docId: string) {
|
||||
@@ -52,7 +59,7 @@ export class SqliteV1DocStorage extends DocStorageBase<{
|
||||
return {
|
||||
docId,
|
||||
bin,
|
||||
timestamp: new Date(),
|
||||
timestamp: CONST_TIMESTAMP,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -69,8 +76,9 @@ export class SqliteV1DocStorage extends DocStorageBase<{
|
||||
const idConverter = await this.getIdConverter();
|
||||
|
||||
return timestamps.reduce(
|
||||
(ret, { docId, timestamp }) => {
|
||||
ret[idConverter.oldIdToNewId(docId ?? this.options.id)] = timestamp;
|
||||
(ret, { docId }) => {
|
||||
ret[idConverter.oldIdToNewId(docId ?? this.options.id)] =
|
||||
CONST_TIMESTAMP;
|
||||
return ret;
|
||||
},
|
||||
{} as Record<string, Date>
|
||||
|
||||
@@ -199,7 +199,8 @@ export class DocSyncPeer {
|
||||
throwIfAborted(signal);
|
||||
if (
|
||||
!this.remote.isReadonly &&
|
||||
(pushedClock === null || pushedClock !== clock?.timestamp)
|
||||
clock &&
|
||||
(pushedClock === null || pushedClock !== clock.timestamp)
|
||||
) {
|
||||
await this.jobs.pullAndPush(docId, signal);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user