Skip to content

Commit 0cb4ad4

Browse files
committed
Skip DB lookup when ownerId provided
1 parent c1ec572 commit 0cb4ad4

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

  • apps/web/app/api/analytics/track

apps/web/app/api/analytics/track/route.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -100,21 +100,23 @@ export async function POST(request: NextRequest) {
100100
},
101101
});
102102

103-
const [videoRecord] = yield* Effect.tryPromise(() =>
104-
db()
105-
.select({ ownerId: videos.ownerId })
106-
.from(videos)
107-
.where(eq(videos.id, Video.VideoId.make(body.videoId)))
108-
.limit(1),
109-
).pipe(Effect.orElseSucceed(() => [] as { ownerId: string }[]));
110-
111-
if (userId && videoRecord && userId === videoRecord.ownerId) {
112-
return;
103+
if (userId && (!body.ownerId || userId === body.ownerId)) {
104+
const [videoRecord] = yield* Effect.tryPromise(() =>
105+
db()
106+
.select({ ownerId: videos.ownerId })
107+
.from(videos)
108+
.where(eq(videos.id, Video.VideoId.make(body.videoId)))
109+
.limit(1),
110+
).pipe(Effect.orElseSucceed(() => [] as { ownerId: string }[]));
111+
112+
if (videoRecord && userId === videoRecord.ownerId) {
113+
return;
114+
}
113115
}
114116

115117
const tenantId =
116118
body.orgId ||
117-
videoRecord?.ownerId ||
119+
body.ownerId ||
118120
(hostname ? `domain:${hostname}` : "public");
119121

120122
const tinybird = yield* Tinybird;

0 commit comments

Comments
 (0)