Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .server-changes/realtimestreams-dedupe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
area: webapp
type: fix
---

Dedupe the `realtimeStreams` array push on `PUT /realtime/v1/streams/:runId/:target/:streamId` so repeat stream-init calls for the same `(run, streamId)` skip the row UPDATE, mirroring the existing append handler.
Original file line number Diff line number Diff line change
Expand Up @@ -62,39 +62,49 @@ const { action } = createActionApiRoute(

if (request.method === "PUT") {
// This is the "create" endpoint
const updatedRun = await prisma.taskRun.update({
const target = await prisma.taskRun.findFirst({
where: {
friendlyId: targetId,
runtimeEnvironmentId: authentication.environment.id,
},
data: {
realtimeStreams: {
push: params.streamId,
},
},
select: {
id: true,
realtimeStreams: true,
realtimeStreamsVersion: true,
completedAt: true,
},
});

if (updatedRun.completedAt) {
if (!target) {
return new Response("Run not found", { status: 404 });
}

if (target.completedAt) {
return new Response("Cannot initialize a realtime stream on a completed run", {
status: 400,
});
}

if (!target.realtimeStreams.includes(params.streamId)) {
await prisma.taskRun.update({
where: { id: target.id },
data: {
realtimeStreams: { push: params.streamId },
},
});
}
Comment thread
ericallam marked this conversation as resolved.

const realtimeStream = getRealtimeStreamInstance(
authentication.environment,
updatedRun.realtimeStreamsVersion,
target.realtimeStreamsVersion,
basinContext
);

const { responseHeaders } = await realtimeStream.initializeStream(targetId, params.streamId);

return json(
{
version: updatedRun.realtimeStreamsVersion,
version: target.realtimeStreamsVersion,
},
{ status: 202, headers: responseHeaders }
);
Expand Down
Loading