From 864768b3ba9a22498f96814d9905c4724d0391b2 Mon Sep 17 00:00:00 2001 From: "Kilu.He" <108015703+qinluhe@users.noreply.github.com> Date: Mon, 22 Jul 2024 15:38:13 +0800 Subject: [PATCH] fix: can not display rows when rows overthan 1000 (#5777) --- .../src/application/database-yjs/selector.ts | 5 +- .../services/js-services/cache/index.ts | 65 ++++++++++--------- .../application/services/js-services/index.ts | 11 +++- 3 files changed, 47 insertions(+), 34 deletions(-) diff --git a/frontend/appflowy_web_app/src/application/database-yjs/selector.ts b/frontend/appflowy_web_app/src/application/database-yjs/selector.ts index 3db157b2fb..c83873b7af 100644 --- a/frontend/appflowy_web_app/src/application/database-yjs/selector.ts +++ b/frontend/appflowy_web_app/src/application/database-yjs/selector.ts @@ -12,7 +12,6 @@ import { useDatabase, useDatabaseFields, useDatabaseView, - useIsDatabaseRowPage, useRowDocMap, useViewId, } from '@/application/database-yjs/context'; @@ -434,7 +433,6 @@ export function useRowsByGroup(groupId: string) { } export function useRowOrdersSelector() { - const isDatabaseRowPage = useIsDatabaseRowPage(); const { rows, clock } = useRowDocMapSelector(); const [rowOrders, setRowOrders] = useState(); const view = useDatabaseView(); @@ -446,7 +444,6 @@ export function useRowOrdersSelector() { if (!originalRowOrders || !rows) return; - if (originalRowOrders.length > rows.size && !isDatabaseRowPage) return; if (sorts?.length === 0 && filters?.length === 0) { setRowOrders(originalRowOrders); return; @@ -467,7 +464,7 @@ export function useRowOrdersSelector() { } else { setRowOrders(originalRowOrders); } - }, [fields, filters, rows, sorts, view, isDatabaseRowPage]); + }, [fields, filters, rows, sorts, view]); useEffect(() => { onConditionsChange(); diff --git a/frontend/appflowy_web_app/src/application/services/js-services/cache/index.ts b/frontend/appflowy_web_app/src/application/services/js-services/cache/index.ts index d33bf9a939..712e903c6b 100644 --- a/frontend/appflowy_web_app/src/application/services/js-services/cache/index.ts +++ b/frontend/appflowy_web_app/src/application/services/js-services/cache/index.ts @@ -12,7 +12,7 @@ import { import { applyYDoc } from '@/application/ydoc/apply'; import { closeCollabDB, db, openCollabDB } from '@/application/db'; import { Fetcher, StrategyType } from '@/application/services/js-services/cache/types'; -import { IndexeddbPersistence } from 'y-indexeddb'; +// import { IndexeddbPersistence } from 'y-indexeddb'; import * as Y from 'yjs'; export function collabTypeToDBType(type: CollabType) { @@ -139,19 +139,19 @@ export async function getPublishView< const doc = await openCollabDB(name); const rowMapDoc = (await openCollabDB(`${name}_rows`)) as Y.Doc; - const subdocs = Array.from(rowMapDoc.getSubdocs()); - - for (const subdoc of subdocs) { - const promise = new Promise((resolve) => { - const persistence = new IndexeddbPersistence(subdoc.guid, subdoc); - - persistence.on('synced', () => { - resolve(true); - }); - }); - - await promise; - } + // const subdocs = Array.from(rowMapDoc.getSubdocs()); + // + // for (const subdoc of subdocs) { + // const promise = new Promise((resolve) => { + // const persistence = new IndexeddbPersistence(subdoc.guid, subdoc); + // + // persistence.on('synced', () => { + // resolve(true); + // }); + // }); + // + // await promise; + // } const exist = (await hasViewMetaCache(name)) && hasCollabCache(doc); @@ -245,14 +245,21 @@ export async function revalidatePublishView< const subdoc = new Y.Doc({ guid: key, }); - const persistence = new IndexeddbPersistence(subdoc.guid, subdoc); - persistence.on('synced', () => { - applyYDoc(subdoc, new Uint8Array(value)); - rowMapDoc.getMap().delete(subdoc.guid); - rowMapDoc.getMap().set(subdoc.guid, subdoc); - }); + applyYDoc(subdoc, new Uint8Array(value)); + rowMapDoc.getMap().delete(subdoc.guid); + rowMapDoc.getMap().set(subdoc.guid, subdoc); + + // const persistence = new IndexeddbPersistence(subdoc.guid, subdoc); + // + // persistence.on('synced', () => { + // applyYDoc(subdoc, new Uint8Array(value)); + // rowMapDoc.getMap().delete(subdoc.guid); + // rowMapDoc.getMap().set(subdoc.guid, subdoc); + // }); } + + console.log('rows', rows); } const state = new Uint8Array(data); @@ -268,15 +275,15 @@ export async function deleteView(name: string) { console.log('deleteView', name); await deleteViewMeta(name); await closeCollabDB(name); - const rowMapDoc = (await openCollabDB(`${name}_rows`)) as Y.Doc; - - const subdocs = Array.from(rowMapDoc.getSubdocs()); - - for (const subdoc of subdocs) { - const persistence = new IndexeddbPersistence(subdoc.guid, subdoc); - - await persistence.destroy(); - } + // const rowMapDoc = (await openCollabDB(`${name}_rows`)) as Y.Doc; + // + // const subdocs = Array.from(rowMapDoc.getSubdocs()); + // + // for (const subdoc of subdocs) { + // const persistence = new IndexeddbPersistence(subdoc.guid, subdoc); + // + // await persistence.destroy(); + // } await closeCollabDB(`${name}_rows`); } diff --git a/frontend/appflowy_web_app/src/application/services/js-services/index.ts b/frontend/appflowy_web_app/src/application/services/js-services/index.ts index 42675d88dc..7ac7cbc256 100644 --- a/frontend/appflowy_web_app/src/application/services/js-services/index.ts +++ b/frontend/appflowy_web_app/src/application/services/js-services/index.ts @@ -38,6 +38,8 @@ export class AFClientService implements AFService { private cacheDatabaseRowDocMap: Map = new Map(); + private cacheDatabaseRowFolder: Map> = new Map(); + constructor(config: AFServiceConfig) { initAPIService({ ...config.cloudConfig, @@ -122,11 +124,18 @@ export class AFClientService implements AFService { return Promise.reject(new Error('Root rows doc not found')); } - const rowsFolder: Y.Map = rootRowsDoc.getMap(); + if (!this.cacheDatabaseRowFolder.has(name)) { + const rowsFolder: Y.Map = rootRowsDoc.getMap(); + + this.cacheDatabaseRowFolder.set(name, rowsFolder); + } + + const rowsFolder = this.cacheDatabaseRowFolder.get(name)!; return { rows: rowsFolder, destroy: () => { + this.cacheDatabaseRowFolder.delete(name); this.cacheDatabaseRowDocMap.delete(name); }, };