feat: enhance DocumentSchema and DocumentService with Redis integration and background processing
- Updated DocumentSchema to include RedisService for improved background processing of grammar checks. - Refactored checkGrammarForPage method in DocumentService to utilize Promise.all for parallel processing and error handling. - Introduced background grammar check functionality with a low probability trigger, enhancing performance and user experience. - Added new utility methods for better time management and error logging. These changes improve the efficiency and responsiveness of the grammar checking feature, leveraging Redis for state management and background processing.
This commit is contained in:
@@ -1,49 +1,58 @@
|
||||
import { Inject, Injectable } from '@nestjs/common'
|
||||
import { Pothos, PothosRef, PothosSchema, SchemaBuilderToken } from '@smatch-corp/nestjs-pothos'
|
||||
import { Builder } from '../Graphql/graphql.builder'
|
||||
import { LiveKitService } from '../LiveKit/livekit.service'
|
||||
import { PrismaService } from '../Prisma/prisma.service'
|
||||
import { Inject, Injectable } from "@nestjs/common";
|
||||
import { ChatRoomType } from "@prisma/client";
|
||||
import {
|
||||
Pothos,
|
||||
PothosRef,
|
||||
PothosSchema,
|
||||
SchemaBuilderToken,
|
||||
} from "@smatch-corp/nestjs-pothos";
|
||||
import { Builder } from "../Graphql/graphql.builder";
|
||||
import { LiveKitService } from "../LiveKit/livekit.service";
|
||||
import { PrismaService } from "../Prisma/prisma.service";
|
||||
@Injectable()
|
||||
export class WorkshopMeetingRoomSchema extends PothosSchema {
|
||||
constructor(
|
||||
@Inject(SchemaBuilderToken) private readonly builder: Builder,
|
||||
private readonly prisma: PrismaService,
|
||||
private readonly livekitService: LiveKitService,
|
||||
private readonly livekitService: LiveKitService
|
||||
) {
|
||||
super()
|
||||
super();
|
||||
}
|
||||
|
||||
@PothosRef()
|
||||
workshopMeetingRoom() {
|
||||
return this.builder.prismaObject('WorkshopMeetingRoom', {
|
||||
return this.builder.prismaObject("WorkshopMeetingRoom", {
|
||||
fields: (t) => ({
|
||||
id: t.exposeID('id', {
|
||||
description: 'The ID of the workshop meeting room.',
|
||||
id: t.exposeID("id", {
|
||||
description: "The ID of the workshop meeting room.",
|
||||
}),
|
||||
workshopId: t.exposeID('workshopId', {
|
||||
description: 'The ID of the workshop that the meeting room is for.',
|
||||
workshopId: t.exposeID("workshopId", {
|
||||
description: "The ID of the workshop that the meeting room is for.",
|
||||
}),
|
||||
workshop: t.relation('workshop', {
|
||||
description: 'The workshop that the meeting room is for.',
|
||||
workshop: t.relation("workshop", {
|
||||
description: "The workshop that the meeting room is for.",
|
||||
}),
|
||||
}),
|
||||
})
|
||||
});
|
||||
}
|
||||
@PothosRef()
|
||||
workshopMeetingRoomJoinInfo() {
|
||||
return this.builder.simpleObject('WorkshopMeetingRoomJoinInfo', {
|
||||
return this.builder.simpleObject("WorkshopMeetingRoomJoinInfo", {
|
||||
fields: (t) => ({
|
||||
id: t.string({
|
||||
description: 'The ID of the workshop meeting room.',
|
||||
description: "The ID of the workshop meeting room.",
|
||||
}),
|
||||
token: t.string({
|
||||
description: 'The token to join the workshop meeting room.',
|
||||
description: "The token to join the workshop meeting room.",
|
||||
}),
|
||||
serverUrl: t.string({
|
||||
description: 'The URL of the server.',
|
||||
description: "The URL of the server.",
|
||||
}),
|
||||
chatRoomId: t.string({
|
||||
description: "The ID of the chat room.",
|
||||
}),
|
||||
}),
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
@Pothos()
|
||||
@@ -51,48 +60,59 @@ export class WorkshopMeetingRoomSchema extends PothosSchema {
|
||||
this.builder.queryFields((t) => ({
|
||||
workshopMeetingRoom: t.prismaField({
|
||||
type: this.workshopMeetingRoom(),
|
||||
args: this.builder.generator.findUniqueArgs('WorkshopMeetingRoom'),
|
||||
args: this.builder.generator.findUniqueArgs("WorkshopMeetingRoom"),
|
||||
resolve: async (query, _root, args, _ctx, _info) => {
|
||||
return await this.prisma.workshopMeetingRoom.findUnique({
|
||||
...query,
|
||||
where: args.where,
|
||||
})
|
||||
});
|
||||
},
|
||||
}),
|
||||
workshopMeetingRoomJoinInfo: t.field({
|
||||
type: this.workshopMeetingRoomJoinInfo(),
|
||||
args: {
|
||||
workshopId: t.arg({
|
||||
type: 'String',
|
||||
type: "String",
|
||||
required: true,
|
||||
}),
|
||||
},
|
||||
resolve: async (_, args, ctx) => {
|
||||
if (ctx.isSubscription) {
|
||||
throw new Error('Not allowed')
|
||||
throw new Error("Not allowed");
|
||||
}
|
||||
if (!ctx.http?.me) {
|
||||
throw new Error('Unauthorized')
|
||||
throw new Error("Unauthorized");
|
||||
}
|
||||
const meetingRoom = await this.prisma.workshopMeetingRoom.findUnique({
|
||||
where: {
|
||||
workshopId: args.workshopId,
|
||||
},
|
||||
})
|
||||
});
|
||||
// query chat room
|
||||
const chatRoom = await this.prisma.chatRoom.findFirst({
|
||||
where: {
|
||||
workshopId: args.workshopId,
|
||||
type: ChatRoomType.WORKSHOP,
|
||||
},
|
||||
});
|
||||
if (!meetingRoom) {
|
||||
throw new Error('Meeting room not found')
|
||||
throw new Error("Meeting room not found");
|
||||
}
|
||||
const serverUrl = this.livekitService.getServerUrl()
|
||||
const serverUrl = this.livekitService.getServerUrl();
|
||||
return {
|
||||
id: meetingRoom.id,
|
||||
token: await this.livekitService.createToken(ctx.http?.me, meetingRoom.id),
|
||||
token: await this.livekitService.createToken(
|
||||
ctx.http?.me,
|
||||
meetingRoom.id
|
||||
),
|
||||
serverUrl,
|
||||
}
|
||||
chatRoomId: chatRoom?.id,
|
||||
};
|
||||
},
|
||||
}),
|
||||
workshopMeetingRooms: t.prismaField({
|
||||
type: [this.workshopMeetingRoom()],
|
||||
args: this.builder.generator.findManyArgs('WorkshopMeetingRoom'),
|
||||
args: this.builder.generator.findManyArgs("WorkshopMeetingRoom"),
|
||||
resolve: async (query, _root, args, _ctx, _info) => {
|
||||
return await this.prisma.workshopMeetingRoom.findMany({
|
||||
...query,
|
||||
@@ -101,9 +121,9 @@ export class WorkshopMeetingRoomSchema extends PothosSchema {
|
||||
cursor: args.cursor ?? undefined,
|
||||
take: args.take ?? undefined,
|
||||
skip: args.skip ?? undefined,
|
||||
})
|
||||
});
|
||||
},
|
||||
}),
|
||||
}))
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user