From 1fcc7b9a5fd84cb567ac008ee2080214416f08de Mon Sep 17 00:00:00 2001 From: Ly Tuan Kiet Date: Wed, 11 Dec 2024 14:43:21 +0700 Subject: [PATCH] refactor: enhance DocumentSchema with detailed field descriptions and adjust random sync logic - Updated DocumentSchema to include detailed descriptions for fields, improving API documentation and usability. - Adjusted the random sync logic threshold from 0.05 to 0.005 to reduce the frequency of sync requests, optimizing performance. - Added new fields for collaboration session management, enhancing document interaction capabilities. --- src/Document/document.schema.ts | 43 ++++++++++++++++++++++++--------- src/main.ts | 2 +- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/src/Document/document.schema.ts b/src/Document/document.schema.ts index 40051a9..e8cd746 100644 --- a/src/Document/document.schema.ts +++ b/src/Document/document.schema.ts @@ -23,16 +23,37 @@ export class DocumentSchema extends PothosSchema { document() { return this.builder.prismaObject('Document', { fields: (t) => ({ - id: t.exposeID('id'), - name: t.exposeString('name'), - fileUrl: t.exposeString('fileUrl'), - previewImage: t.relation('previewImage', { nullable: true }), - createdAt: t.expose('createdAt', { type: 'DateTime' }), - updatedAt: t.expose('updatedAt', { type: 'DateTime' }), - owner: t.relation('owner'), - ownerId: t.exposeID('ownerId'), - collaborators: t.relation('collaborators'), - isPublic: t.exposeBoolean('isPublic'), + id: t.exposeID('id', { description: 'The ID of the document.', nullable: false }), + name: t.exposeString('name', { description: 'The name of the document.', nullable: false }), + fileUrl: t.exposeString('fileUrl', { description: 'The file URL of the document.', nullable: false }), + previewImage: t.relation('previewImage', { + description: 'The preview image of the document.', + nullable: true, + }), + owner: t.relation('owner', { description: 'The owner of the document.', nullable: false }), + collaborators: t.relation('collaborators', { + description: 'The collaborators of the document.', + nullable: false, + }), + isPublic: t.exposeBoolean('isPublic', { description: 'Whether the document is public.', nullable: false }), + collaborationSession: t.relation('collaborationSession', { + description: 'The collaboration session of the document.', + nullable: true, + }), + collaborationSessionId: t.exposeID('collaborationSessionId', { + description: 'The ID of the collaboration session of the document.', + nullable: true, + }), + createdAt: t.expose('createdAt', { + description: 'The creation time of the document.', + type: 'DateTime', + nullable: false, + }), + updatedAt: t.expose('updatedAt', { + description: 'The update time of the document.', + type: 'DateTime', + nullable: false, + }), }), }) } @@ -524,7 +545,7 @@ export class DocumentSchema extends PothosSchema { // using randomize sync mechanism to avoid performance issue const random = Math.random() // 0.5% chance to request sync - if (random <= 0.05) { + if (random <= 0.005) { // check grammar too this.documentService.checkGrammarForPage(payload.documentId, payload.pageIndex) Logger.log('request sync', 'request sync') diff --git a/src/main.ts b/src/main.ts index 661e917..e028b5c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -71,7 +71,7 @@ async function bootstrap() { maxFiles: 10, }), ) - // biome-ignore lint/suspicious/noExplicitAny: + // biome-ignore lint/suspicious/noExplicitAny: error type should be any to get the error message } catch (error: any) { Logger.error(`Error in file upload middleware: ${error.message}`, 'Bootstrap') // Optionally, you can handle the error further or rethrow it