( websiteId: string )
| 476 | } |
| 477 | |
| 478 | export async function getWebsiteOnlineUserCount( |
| 479 | websiteId: string |
| 480 | ): Promise<number> { |
| 481 | const startAt = dayjs().subtract(5, 'minutes').toDate(); |
| 482 | |
| 483 | interface Ret { |
| 484 | x: number; |
| 485 | } |
| 486 | |
| 487 | const res = await prisma.$queryRaw< |
| 488 | Ret[] |
| 489 | >`SELECT count(distinct "sessionId") x FROM "WebsiteEvent" where "websiteId" = ${websiteId} AND "createdAt" >= ${startAt}`; |
| 490 | |
| 491 | return Number(res?.[0].x ?? 0); |
| 492 | } |
| 493 | |
| 494 | export async function getWebsiteSessionMetrics( |
| 495 | websiteId: string, |