Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

Skip DB lookup when ownerId provided

Richie McIlroy0cb4ad4684b3
diff --git a/apps/web/app/api/analytics/track/route.ts b/apps/web/app/api/analytics/track/route.ts
index 52fb22e95..72bdc137b 100644
--- a/apps/web/app/api/analytics/track/route.ts
+++ b/apps/web/app/api/analytics/track/route.ts
@@ -100,21 +100,23 @@ export async function POST(request: NextRequest) {
},
});
- const [videoRecord] = yield* Effect.tryPromise(() =>
- db()
- .select({ ownerId: videos.ownerId })
- .from(videos)
- .where(eq(videos.id, Video.VideoId.make(body.videoId)))
- .limit(1),
- ).pipe(Effect.orElseSucceed(() => [] as { ownerId: string }[]));
-
- if (userId && videoRecord && userId === videoRecord.ownerId) {
- return;
+ if (userId && (!body.ownerId || userId === body.ownerId)) {
+ const [videoRecord] = yield* Effect.tryPromise(() =>
+ db()
+ .select({ ownerId: videos.ownerId })
+ .from(videos)
+ .where(eq(videos.id, Video.VideoId.make(body.videoId)))
+ .limit(1),
+ ).pipe(Effect.orElseSucceed(() => [] as { ownerId: string }[]));
+
+ if (videoRecord && userId === videoRecord.ownerId) {
+ return;
+ }
}
const tenantId =
body.orgId ||
- videoRecord?.ownerId ||
+ body.ownerId ||
(hostname ? `domain:${hostname}` : "public");
const tinybird = yield* Tinybird;