mirror of
https://github.com/Hessenuk/DiscordTickets.git
synced 2024-12-23 00:03:09 +02:00
fix: response & resolution time stats
This commit is contained in:
parent
a953308532
commit
ced14ce36a
@ -406,9 +406,17 @@ module.exports = class TicketManager {
|
|||||||
const statsCacheKey = `cache/category-stats/${categoryId}`;
|
const statsCacheKey = `cache/category-stats/${categoryId}`;
|
||||||
let stats = await this.client.keyv.get(statsCacheKey);
|
let stats = await this.client.keyv.get(statsCacheKey);
|
||||||
if (!stats) {
|
if (!stats) {
|
||||||
const { tickets } = await this.client.prisma.category.findUnique({
|
const tickets = await this.client.prisma.ticket.findMany({
|
||||||
select: { tickets: { where: { open: false } } },
|
select: {
|
||||||
where: { id: categoryId },
|
closedAt: true,
|
||||||
|
createdAt: true,
|
||||||
|
firstResponseAt: true,
|
||||||
|
},
|
||||||
|
where: {
|
||||||
|
categoryId: category.id,
|
||||||
|
firstResponseAt: { not: null },
|
||||||
|
open: false,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
stats = {
|
stats = {
|
||||||
avgResolutionTime: ms(tickets.reduce((total, ticket) => total + (ticket.closedAt - ticket.createdAt), 0) ?? 1 / tickets.length),
|
avgResolutionTime: ms(tickets.reduce((total, ticket) => total + (ticket.closedAt - ticket.createdAt), 0) ?? 1 / tickets.length),
|
||||||
|
@ -33,11 +33,12 @@ module.exports = class extends Listener {
|
|||||||
if (!cached) {
|
if (!cached) {
|
||||||
const tickets = await client.prisma.ticket.findMany({
|
const tickets = await client.prisma.ticket.findMany({
|
||||||
select: {
|
select: {
|
||||||
|
closedAt: true,
|
||||||
createdAt: true,
|
createdAt: true,
|
||||||
firstResponseAt: true,
|
firstResponseAt: true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const closedTickets = tickets.filter(t => t.closedAt);
|
const closedTickets = tickets.filter(t => t.firstResponseAt && t.closedAt);
|
||||||
cached = {
|
cached = {
|
||||||
avgResolutionTime: ms(closedTickets.reduce((total, ticket) => total + (ticket.closedAt - ticket.createdAt), 0) ?? 1 / closedTickets.length),
|
avgResolutionTime: ms(closedTickets.reduce((total, ticket) => total + (ticket.closedAt - ticket.createdAt), 0) ?? 1 / closedTickets.length),
|
||||||
avgResponseTime: ms(closedTickets.reduce((total, ticket) => total + (ticket.firstResponseAt - ticket.createdAt), 0) ?? 1 / closedTickets.length),
|
avgResponseTime: ms(closedTickets.reduce((total, ticket) => total + (ticket.firstResponseAt - ticket.createdAt), 0) ?? 1 / closedTickets.length),
|
||||||
|
@ -29,7 +29,7 @@ module.exports.get = fastify => ({
|
|||||||
where: { id: req.params.guild },
|
where: { id: req.params.guild },
|
||||||
});
|
});
|
||||||
categories = categories.map(c => {
|
categories = categories.map(c => {
|
||||||
const closedTickets = c.tickets.filter(t => t.closedAt);
|
const closedTickets = c.tickets.filter(t => t.firstResponseAt && t.closedAt);
|
||||||
c = {
|
c = {
|
||||||
...c,
|
...c,
|
||||||
stats: {
|
stats: {
|
||||||
|
@ -23,12 +23,13 @@ module.exports.get = fastify => ({
|
|||||||
});
|
});
|
||||||
const tickets = await client.prisma.ticket.findMany({
|
const tickets = await client.prisma.ticket.findMany({
|
||||||
select: {
|
select: {
|
||||||
|
closedAt: true,
|
||||||
createdAt: true,
|
createdAt: true,
|
||||||
firstResponseAt: true,
|
firstResponseAt: true,
|
||||||
},
|
},
|
||||||
where: { guildId: id },
|
where: { guildId: id },
|
||||||
});
|
});
|
||||||
const closedTickets = tickets.filter(t => t.closedAt);
|
const closedTickets = tickets.filter(t => t.firstResponseAt && t.closedAt);
|
||||||
cached = {
|
cached = {
|
||||||
createdAt: settings.createdAt,
|
createdAt: settings.createdAt,
|
||||||
id: guild.id,
|
id: guild.id,
|
||||||
@ -46,7 +47,7 @@ module.exports.get = fastify => ({
|
|||||||
tickets: tickets.length,
|
tickets: tickets.length,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
await client.keyv.set(cacheKey, cached, ms('5m'));
|
// await client.keyv.set(cacheKey, cached, ms('5m'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return cached;
|
return cached;
|
||||||
|
@ -10,11 +10,12 @@ module.exports.get = () => ({
|
|||||||
if (!cached) {
|
if (!cached) {
|
||||||
const tickets = await client.prisma.ticket.findMany({
|
const tickets = await client.prisma.ticket.findMany({
|
||||||
select: {
|
select: {
|
||||||
|
closedAt: true,
|
||||||
createdAt: true,
|
createdAt: true,
|
||||||
firstResponseAt: true,
|
firstResponseAt: true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const closedTickets = tickets.filter(t => t.closedAt);
|
const closedTickets = tickets.filter(t => t.firstResponseAt && t.closedAt);
|
||||||
const users = await client.prisma.user.findMany({ select: { messageCount: true } });
|
const users = await client.prisma.user.findMany({ select: { messageCount: true } });
|
||||||
cached = {
|
cached = {
|
||||||
avatar: client.user.avatarURL(),
|
avatar: client.user.avatarURL(),
|
||||||
|
Loading…
Reference in New Issue
Block a user