Skip to content

Commit 7f72589

Browse files
committed
Runs filter by org id and add created at to ordering
1 parent 8a5e7f3 commit 7f72589

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export class NextRunListPresenter {
4545
) {}
4646

4747
public async call(
48+
organizationId: string,
4849
environmentId: string,
4950
{
5051
userId,
@@ -190,6 +191,7 @@ export class NextRunListPresenter {
190191
});
191192

192193
const { runs, pagination } = await runsRepository.listRuns({
194+
organizationId,
193195
environmentId,
194196
projectId,
195197
tasks,

apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.next.runs._index/route.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {
128128
}
129129

130130
const presenter = new NextRunListPresenter($replica, clickhouseClient);
131-
const list = presenter.call(environment.id, {
131+
const list = presenter.call(project.organizationId, environment.id, {
132132
userId,
133133
projectId: project.id,
134134
tasks,

apps/webapp/app/services/runsRepository.server.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { ClickHouse } from "@internal/clickhouse";
2-
import { Tracer } from "@internal/tracing";
3-
import { Logger, LogLevel } from "@trigger.dev/core/logger";
4-
import { TaskRunStatus } from "@trigger.dev/database";
5-
import { PrismaClient } from "~/db.server";
1+
import { type ClickHouse } from "@internal/clickhouse";
2+
import { type Tracer } from "@internal/tracing";
3+
import { type Logger, type LogLevel } from "@trigger.dev/core/logger";
4+
import { type TaskRunStatus } from "@trigger.dev/database";
5+
import { type PrismaClient } from "~/db.server";
66

77
export type RunsRepositoryOptions = {
88
clickhouse: ClickHouse;
@@ -13,6 +13,7 @@ export type RunsRepositoryOptions = {
1313
};
1414

1515
export type ListRunsOptions = {
16+
organizationId: string;
1617
projectId: string;
1718
environmentId: string;
1819
//filters
@@ -43,11 +44,14 @@ export class RunsRepository {
4344
async listRuns(options: ListRunsOptions) {
4445
const queryBuilder = this.options.clickhouse.taskRuns.queryBuilder();
4546
queryBuilder
46-
.where("environment_id = {environmentId: String}", {
47-
environmentId: options.environmentId,
47+
.where("organization_id = {organizationId: String}", {
48+
organizationId: options.organizationId,
4849
})
4950
.where("project_id = {projectId: String}", {
5051
projectId: options.projectId,
52+
})
53+
.where("environment_id = {environmentId: String}", {
54+
environmentId: options.environmentId,
5155
});
5256

5357
if (options.tasks && options.tasks.length > 0) {
@@ -115,17 +119,17 @@ export class RunsRepository {
115119
if (options.page.direction === "forward") {
116120
queryBuilder
117121
.where("run_id < {runId: String}", { runId: options.page.cursor })
118-
.orderBy("run_id DESC")
122+
.orderBy("created_at DESC, run_id DESC")
119123
.limit(options.page.size + 1);
120124
} else {
121125
queryBuilder
122126
.where("run_id > {runId: String}", { runId: options.page.cursor })
123-
.orderBy("run_id DESC")
127+
.orderBy("created_at DESC, run_id DESC")
124128
.limit(options.page.size + 1);
125129
}
126130
} else {
127131
// Initial page - no cursor provided
128-
queryBuilder.orderBy("run_id DESC").limit(options.page.size + 1);
132+
queryBuilder.orderBy("created_at DESC, run_id DESC").limit(options.page.size + 1);
129133
}
130134

131135
const [queryError, result] = await queryBuilder.execute();

0 commit comments

Comments
 (0)