Skip to content

Commit 3d5cfbb

Browse files
committed
⚡️(frontend) fetch document without content when not needed
To improve performance, especially for documents with large content, an optional query parameter `without_content` has been added to the document fetching API endpoint. When this parameter is set to true, the API will return the document metadata without the content, allowing the frontend to load faster and reduce unnecessary data transfer.
1 parent c5ef18e commit 3d5cfbb

File tree

5 files changed

+17
-8
lines changed

5 files changed

+17
-8
lines changed

src/frontend/apps/impress/src/features/docs/doc-editor/components/custom-inline-content/Interlinking/InterlinkingLinkInlineContent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export const LinkSelected = ({
9595
isEditable,
9696
updateInlineContent,
9797
}: LinkSelectedProps) => {
98-
const { data: doc } = useDoc({ id: docId });
98+
const { data: doc } = useDoc({ id: docId, withoutContent: true });
9999

100100
/**
101101
* Update the content title if the referenced doc title changes

src/frontend/apps/impress/src/features/docs/doc-management/api/useDoc.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,15 @@ import { Doc } from '../types';
66

77
export type DocParams = {
88
id: string;
9+
withoutContent?: boolean;
910
};
1011

11-
export const getDoc = async ({ id }: DocParams): Promise<Doc> => {
12-
const response = await fetchAPI(`documents/${id}/`);
12+
export const getDoc = async ({
13+
id,
14+
withoutContent,
15+
}: DocParams): Promise<Doc> => {
16+
const params = withoutContent ? '?without_content=true' : '';
17+
const response = await fetchAPI(`documents/${id}/${params}`);
1318

1419
if (!response.ok) {
1520
throw new APIError('Failed to get the doc', await errorCauses(response));

src/frontend/apps/impress/src/features/docs/doc-management/types.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export interface Doc {
5353
title?: string;
5454
children?: Doc[];
5555
childrenCount?: number;
56-
content: Base64;
56+
content?: Base64;
5757
created_at: string;
5858
creator: string;
5959
deleted_at: string | null;

src/frontend/servers/y-provider/src/api/collaborationBackend.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type Base64 = string;
1717
interface Doc {
1818
id: string;
1919
title?: string;
20-
content: Base64;
20+
content?: Base64;
2121
creator: string;
2222
is_favorite: boolean;
2323
link_reach: 'restricted' | 'public' | 'authenticated';
@@ -74,10 +74,11 @@ async function fetch<T>(
7474
}
7575

7676
export function fetchDocument(
77-
name: string,
77+
{ name, withoutContent }: { name: string; withoutContent?: boolean },
7878
requestHeaders: IncomingHttpHeaders,
7979
): Promise<Doc> {
80-
return fetch<Doc>(`/api/v1.0/documents/${name}/`, requestHeaders);
80+
const params = withoutContent ? '?without_content=true' : '';
81+
return fetch<Doc>(`/api/v1.0/documents/${name}/${params}`, requestHeaders);
8182
}
8283

8384
export function fetchCurrentUser(

src/frontend/servers/y-provider/src/servers/hocuspocusServer.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ export const hocuspocusServer = new Server({
3939
let canEdit = false;
4040

4141
try {
42-
const document = await fetchDocument(documentName, requestHeaders);
42+
const document = await fetchDocument(
43+
{ name: documentName, withoutContent: true },
44+
requestHeaders,
45+
);
4346

4447
if (!document.abilities.retrieve) {
4548
logger(

0 commit comments

Comments
 (0)