Skip to content

Commit

Permalink
debug reply
Browse files Browse the repository at this point in the history
  • Loading branch information
uffy committed Aug 3, 2024
1 parent dd8d073 commit 67a6938
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
12 changes: 12 additions & 0 deletions next/api/src/model/Ticket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,9 @@ export class Ticket extends Model {
}
}

const replyCreateStart = performance.now();
console.log("ticket.reply (create-start)", this.id, new Date());

const reply = await Reply.create(
{
ACL,
Expand All @@ -308,6 +311,9 @@ export class Ticket extends Model {
}
);

const replyCreateEnd = performance.now()
console.log("ticket.reply (create-end)", this.id, new Date(), replyCreateEnd - replyCreateStart);

const updater = new TicketUpdater(this);
if (isCustomerService && data.author !== systemUser) {
updater.addJoinedCustomerService(data.author.getTinyInfo());
Expand Down Expand Up @@ -340,6 +346,9 @@ export class Ticket extends Model {
currentUserId: data.author.id,
});

const emitEventEnd = performance.now()
console.log("ticket.reply (emit-event)", this.id, new Date(), emitEventEnd - replyCreateEnd);

if (!data.internal) {
if (this.channel === 'email' && data.author.id !== this.authorId) {
// 向创建者发送邮件
Expand All @@ -349,6 +358,9 @@ export class Ticket extends Model {
}
}

const sendEmailEnd = performance.now()
console.log("ticket.reply (send-email)", this.id, new Date(), sendEmailEnd - emitEventEnd);

return reply;
}

Expand Down
32 changes: 21 additions & 11 deletions next/api/src/router/ticket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,8 @@ router.post('/:id/replies', async (ctx) => {
const currentUser = ctx.state.currentUser as User;
const ticket = ctx.state.ticket as Ticket;

const serveStart = performance.now();

console.log("POST replies", ticket.id, new Date())

const data = replyDataSchema.validateSync(ctx.request.body);
Expand Down Expand Up @@ -882,24 +884,32 @@ router.post('/:id/replies', async (ctx) => {
ctx.throw(400, 'Content and fileIds cannot be empty at the same time');
}

console.log("POST replies (before reply)", ticket.id, new Date())
const validateEnd = performance.now();

console.log("POST replies (before reply)", ticket.id, new Date(), validateEnd - serveStart)

const content = isCustomerService
? data.content
: (
await textFilterService.filter(data.content, {
user_id: currentUser.username,
ip: getIP(ctx),
nickname: currentUser.name,
})
).escape

const textFilterEnd = performance.now();
console.log("POST replies (text-filter)", ticket.id, new Date(), textFilterEnd - validateEnd)

const reply = await ticket.reply({
author: currentUser,
content: isCustomerService
? data.content
: (
await textFilterService.filter(data.content, {
user_id: currentUser.username,
ip: getIP(ctx),
nickname: currentUser.name,
})
).escape,
content: content,
fileIds: data.fileIds?.length ? data.fileIds : undefined,
internal: data.internal,
});

console.log("POST replies (after reply)", ticket.id, new Date())
const replyEnd = performance.now();
console.log("POST replies (after reply)", ticket.id, new Date(), replyEnd - textFilterEnd)

ctx.body = new ReplyResponse(reply);
});
Expand Down

0 comments on commit 67a6938

Please sign in to comment.