Skip to content

Commit 6ca66b7

Browse files
committed
Remove unnecessary transaction from the runtime environment session handling
1 parent 29ef039 commit 6ca66b7

File tree

1 file changed

+43
-47
lines changed

1 file changed

+43
-47
lines changed

apps/webapp/app/models/runtimeEnvironment.server.ts

Lines changed: 43 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -65,59 +65,55 @@ export async function findEnvironmentById(id: string) {
6565
}
6666

6767
export async function createNewSession(environment: RuntimeEnvironment, ipAddress: string) {
68-
return prisma.$transaction(async (tx) => {
69-
const session = await tx.runtimeEnvironmentSession.create({
70-
data: {
71-
environmentId: environment.id,
72-
ipAddress,
73-
},
74-
});
75-
76-
await tx.runtimeEnvironment.update({
77-
where: {
78-
id: environment.id,
79-
},
80-
data: {
81-
currentSessionId: session.id,
82-
},
83-
});
84-
85-
return session;
68+
const session = await prisma.runtimeEnvironmentSession.create({
69+
data: {
70+
environmentId: environment.id,
71+
ipAddress,
72+
},
73+
});
74+
75+
await prisma.runtimeEnvironment.update({
76+
where: {
77+
id: environment.id,
78+
},
79+
data: {
80+
currentSessionId: session.id,
81+
},
8682
});
83+
84+
return session;
8785
}
8886

8987
export async function disconnectSession(environmentId: string) {
90-
return prisma.$transaction(async (tx) => {
91-
const environment = await tx.runtimeEnvironment.findUnique({
92-
where: {
93-
id: environmentId,
94-
},
95-
});
96-
97-
if (!environment || !environment.currentSessionId) {
98-
return null;
99-
}
88+
const environment = await prisma.runtimeEnvironment.findUnique({
89+
where: {
90+
id: environmentId,
91+
},
92+
});
10093

101-
const session = await tx.runtimeEnvironmentSession.update({
102-
where: {
103-
id: environment.currentSessionId,
104-
},
105-
data: {
106-
disconnectedAt: new Date(),
107-
},
108-
});
109-
110-
await tx.runtimeEnvironment.update({
111-
where: {
112-
id: environment.id,
113-
},
114-
data: {
115-
currentSessionId: null,
116-
},
117-
});
118-
119-
return session;
94+
if (!environment || !environment.currentSessionId) {
95+
return null;
96+
}
97+
98+
const session = await prisma.runtimeEnvironmentSession.update({
99+
where: {
100+
id: environment.currentSessionId,
101+
},
102+
data: {
103+
disconnectedAt: new Date(),
104+
},
120105
});
106+
107+
await prisma.runtimeEnvironment.update({
108+
where: {
109+
id: environment.id,
110+
},
111+
data: {
112+
currentSessionId: null,
113+
},
114+
});
115+
116+
return session;
121117
}
122118

123119
type DisplayableInputEnvironment = Prisma.RuntimeEnvironmentGetPayload<{

0 commit comments

Comments
 (0)