Skip to content

Commit 2b3c9ac

Browse files
committed
Switch to read replica: ScheduleListPresenter
1 parent 7d05490 commit 2b3c9ac

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

apps/webapp/app/presenters/v3/ScheduleListPresenter.server.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { PrismaClient, prisma, sqlDatabaseSchema } from "~/db.server";
44
import { displayableEnvironment } from "~/models/runtimeEnvironment.server";
55
import { getUsername } from "~/utils/username";
66
import { calculateNextScheduledTimestamp } from "~/v3/utils/calculateNextSchedule.server";
7+
import { BasePresenter } from "./basePresenter.server";
78

89
type ScheduleListOptions = {
910
projectId: string;
@@ -34,12 +35,7 @@ export type ScheduleListItem = {
3435
export type ScheduleList = Awaited<ReturnType<ScheduleListPresenter["call"]>>;
3536
export type ScheduleListAppliedFilters = ScheduleList["filters"];
3637

37-
export class ScheduleListPresenter {
38-
#prismaClient: PrismaClient;
39-
40-
constructor(prismaClient: PrismaClient = prisma) {
41-
this.#prismaClient = prismaClient;
42-
}
38+
export class ScheduleListPresenter extends BasePresenter {
4339

4440
public async call({
4541
userId,
@@ -54,7 +50,7 @@ export class ScheduleListPresenter {
5450
tasks !== undefined || environments !== undefined || (search !== undefined && search !== "");
5551

5652
// Find the project scoped to the organization
57-
const project = await this.#prismaClient.project.findFirstOrThrow({
53+
const project = await this._replica.project.findFirstOrThrow({
5854
select: {
5955
id: true,
6056
environments: {
@@ -82,7 +78,7 @@ export class ScheduleListPresenter {
8278
});
8379

8480
//get all possible scheduled tasks
85-
const possibleTasks = await this.#prismaClient.backgroundWorkerTask.findMany({
81+
const possibleTasks = await this._replica.backgroundWorkerTask.findMany({
8682
distinct: ["slug"],
8783
where: {
8884
projectId: project.id,
@@ -93,7 +89,7 @@ export class ScheduleListPresenter {
9389
//do this here to protect against SQL injection
9490
search = search && search !== "" ? `%${search}%` : undefined;
9591

96-
const totalCount = await this.#prismaClient.taskSchedule.count({
92+
const totalCount = await this._replica.taskSchedule.count({
9793
where: {
9894
projectId: project.id,
9995
taskIdentifier: tasks ? { in: tasks } : undefined,
@@ -135,7 +131,7 @@ export class ScheduleListPresenter {
135131
},
136132
});
137133

138-
const rawSchedules = await this.#prismaClient.taskSchedule.findMany({
134+
const rawSchedules = await this._replica.taskSchedule.findMany({
139135
select: {
140136
id: true,
141137
friendlyId: true,
@@ -199,7 +195,7 @@ export class ScheduleListPresenter {
199195

200196
const latestRuns =
201197
rawSchedules.length > 0
202-
? await this.#prismaClient.$queryRaw<{ scheduleId: string; createdAt: Date }[]>`
198+
? await this._replica.$queryRaw<{ scheduleId: string; createdAt: Date }[]>`
203199
SELECT t."scheduleId", t."createdAt"
204200
FROM (
205201
SELECT "scheduleId", MAX("createdAt") as "LatestRun"

0 commit comments

Comments
 (0)