fix: can not display rows when rows overthan 1000 (#5777)

This commit is contained in:
Kilu.He 2024-07-22 15:38:13 +08:00 committed by GitHub
parent a8b4f22703
commit 864768b3ba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 47 additions and 34 deletions

View File

@ -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<Row[]>();
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();

View File

@ -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`);
}

View File

@ -38,6 +38,8 @@ export class AFClientService implements AFService {
private cacheDatabaseRowDocMap: Map<string, Y.Doc> = new Map();
private cacheDatabaseRowFolder: Map<string, Y.Map<YDoc>> = 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<YDoc> = rootRowsDoc.getMap();
if (!this.cacheDatabaseRowFolder.has(name)) {
const rowsFolder: Y.Map<YDoc> = 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);
},
};