mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-11 05:58:56 +08:00
fix(core): migration (#3322)
This commit is contained in:
@@ -81,9 +81,30 @@ const rootWorkspacesMetadataPromiseAtom = atom<
|
|||||||
// fixme(himself65): we might not need step 1
|
// fixme(himself65): we might not need step 1
|
||||||
// step 1: try load metadata from localStorage
|
// step 1: try load metadata from localStorage
|
||||||
{
|
{
|
||||||
|
const loadFromLocalStorage = (): RootWorkspaceMetadata[] => {
|
||||||
|
// don't change this key,
|
||||||
|
// otherwise it will cause the data loss in the production
|
||||||
|
const primitiveMetadata = localStorage.getItem(METADATA_STORAGE_KEY);
|
||||||
|
if (primitiveMetadata) {
|
||||||
|
try {
|
||||||
|
const items = JSON.parse(primitiveMetadata) as z.infer<
|
||||||
|
typeof rootWorkspaceMetadataArraySchema
|
||||||
|
>;
|
||||||
|
rootWorkspaceMetadataArraySchema.parse(items);
|
||||||
|
return [...items];
|
||||||
|
} catch (e) {
|
||||||
|
console.error('cannot parse worksapce', e);
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
};
|
||||||
|
|
||||||
|
const maybeMetadata = loadFromLocalStorage();
|
||||||
|
|
||||||
// migration step, only data in `METADATA_STORAGE_KEY` will be migrated
|
// migration step, only data in `METADATA_STORAGE_KEY` will be migrated
|
||||||
if (
|
if (
|
||||||
metadata.some(meta => !('version' in meta)) &&
|
maybeMetadata.some(meta => !('version' in meta)) &&
|
||||||
!globalThis.$migrationDone
|
!globalThis.$migrationDone
|
||||||
) {
|
) {
|
||||||
await new Promise<void>((resolve, reject) => {
|
await new Promise<void>((resolve, reject) => {
|
||||||
@@ -94,20 +115,7 @@ const rootWorkspacesMetadataPromiseAtom = atom<
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// don't change this key,
|
metadata.push(...loadFromLocalStorage());
|
||||||
// otherwise it will cause the data loss in the production
|
|
||||||
const primitiveMetadata = localStorage.getItem(METADATA_STORAGE_KEY);
|
|
||||||
if (primitiveMetadata) {
|
|
||||||
try {
|
|
||||||
const items = JSON.parse(primitiveMetadata) as z.infer<
|
|
||||||
typeof rootWorkspaceMetadataArraySchema
|
|
||||||
>;
|
|
||||||
rootWorkspaceMetadataArraySchema.parse(items);
|
|
||||||
metadata.push(...items);
|
|
||||||
} catch (e) {
|
|
||||||
console.error('cannot parse worksapce', e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// step 2: fetch from adapters
|
// step 2: fetch from adapters
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -84,8 +84,6 @@ test('init page', async ({ page, context }) => {
|
|||||||
await switchToNext();
|
await switchToNext();
|
||||||
await page.waitForTimeout(1000);
|
await page.waitForTimeout(1000);
|
||||||
await page.goto('http://localhost:8081/');
|
await page.goto('http://localhost:8081/');
|
||||||
await page.waitForTimeout(1000);
|
|
||||||
await page.goto('http://localhost:8081/');
|
|
||||||
await page.waitForSelector('v-line', {
|
await page.waitForSelector('v-line', {
|
||||||
timeout: 10000,
|
timeout: 10000,
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user