We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b029358 commit 47856c0Copy full SHA for 47856c0
1 file changed
apps/backend/src/routes/analytics.ts
@@ -70,13 +70,14 @@ export async function analyticsRoutes(
70
// Count unique viewers
71
// In raw SQL this is `SELECT COUNT(DISTINCT viewer_id) FROM card_views WHERE owner_id = ?`
72
// Prisma group-by as workaround:
73
- const uniqueViewersQuery =
74
- await app.prisma.cardView.groupBy({
75
- by: ['viewerId', 'viewerIp'],
76
- where: { ownerId: userId },
77
- });
78
-
79
- const uniqueViewers = uniqueViewersQuery.length;
+ const uniqueViewersQuery = await app.prisma.$queryRaw<[{ count: bigint }]>`
+ SELECT COUNT(DISTINCT viewer_id) AS count
+ FROM card_views
+ WHERE owner_id = ${userId}
+ AND viewer_id IS NOT NULL
+ `;
+
80
+ const uniqueViewers = Number(uniqueViewersQuery[0]?.count ?? 0);
81
82
return {
83
totalViews,
0 commit comments