Skip to content

Commit dff5e7d

Browse files
committed
WIP on tags listing
1 parent 5e9f3e6 commit dff5e7d

6 files changed

+61
-19
lines changed

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@ import { RunsRepository } from "~/services/runsRepository/runsRepository.server"
22
import { BasePresenter } from "./basePresenter.server";
33
import { clickhouseClient } from "~/services/clickhouseInstance.server";
44
import { type PrismaClient } from "@trigger.dev/database";
5+
import { timeFilters } from "~/components/runs/v3/SharedFilters";
56

67
export type TagListOptions = {
78
organizationId: string;
89
environmentId: string;
910
projectId: string;
10-
createdAfter?: Date;
11+
period?: string;
12+
from?: Date;
13+
to?: Date;
1114
//filters
1215
name?: string;
1316
//pagination
@@ -26,7 +29,9 @@ export class RunTagListPresenter extends BasePresenter {
2629
environmentId,
2730
projectId,
2831
name,
29-
createdAfter,
32+
period,
33+
from,
34+
to,
3035
page = 1,
3136
pageSize = DEFAULT_PAGE_SIZE,
3237
}: TagListOptions) {
@@ -37,15 +42,14 @@ export class RunTagListPresenter extends BasePresenter {
3742
prisma: this._replica as PrismaClient,
3843
});
3944

40-
// Passed in or past 30 days
41-
const createdAt = createdAfter ?? new Date(Date.now() - 30 * 24 * 60 * 60 * 1000);
42-
4345
const tags = await runsRepository.listTags({
4446
organizationId,
4547
projectId,
4648
environmentId,
4749
query: name,
48-
createdAfter: createdAt,
50+
period,
51+
from: from ? from.getTime() : undefined,
52+
to: to ? to.getTime() : undefined,
4953
offset: (page - 1) * pageSize,
5054
limit: pageSize + 1,
5155
});

apps/webapp/app/routes/resources.environments.$envId.runs.tags.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { type LoaderFunctionArgs } from "@remix-run/server-runtime";
22
import { z } from "zod";
3+
import { timeFilters } from "~/components/runs/v3/SharedFilters";
34
import { $replica } from "~/db.server";
45
import { RunTagListPresenter } from "~/presenters/v3/RunTagListPresenter.server";
56
import { requireUserId } from "~/services/session.server";
@@ -34,9 +35,6 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
3435

3536
const search = new URL(request.url).searchParams;
3637
const name = search.get("name");
37-
const period = search.get("period");
38-
const from = search.get("from");
39-
const to = search.get("to");
4038

4139
const parsedSearchParams = SearchParams.safeParse({
4240
name: name ? decodeURIComponent(name) : undefined,
@@ -49,13 +47,21 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
4947
throw new Response("Invalid search params", { status: 400 });
5048
}
5149

50+
const { period, from, to } = timeFilters({
51+
period: parsedSearchParams.data.period,
52+
from: parsedSearchParams.data.from,
53+
to: parsedSearchParams.data.to,
54+
});
55+
5256
const presenter = new RunTagListPresenter();
5357
const result = await presenter.call({
5458
environmentId: environment.id,
5559
projectId: environment.projectId,
5660
organizationId: environment.organizationId,
5761
name: parsedSearchParams.data.name,
58-
createdAfter: parsedSearchParams.data.createdAfter,
62+
period,
63+
from,
64+
to,
5965
});
6066
return result;
6167
}

apps/webapp/app/routes/resources.orgs.$organizationSlug.projects.$projectParam.env.$envParam.runs.ai-filter.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,16 @@ export async function action({ request, params }: ActionFunctionArgs) {
6565
query: async (search) => {
6666
const tagPresenter = new RunTagListPresenter();
6767
const tags = await tagPresenter.call({
68+
organizationId: environment.organizationId,
6869
projectId: environment.projectId,
70+
environmentId: environment.id,
6971
name: search,
7072
page: 1,
7173
pageSize: 50,
74+
period: "1y",
7275
});
7376
return {
74-
tags: tags.tags.map((t) => t.name),
77+
tags: tags.tags,
7578
};
7679
},
7780
};

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import {
66
type ListRunsOptions,
77
type RunListInputOptions,
88
type RunsRepositoryOptions,
9-
TagListOptions,
9+
type TagListOptions,
1010
convertRunListInputOptionsToFilterRunsOptions,
1111
} from "./runsRepository.server";
12+
import parseDuration from "parse-duration";
1213

1314
export class ClickHouseRunsRepository implements IRunsRepository {
1415
constructor(private readonly options: RunsRepositoryOptions) {}
@@ -177,6 +178,23 @@ export class ClickHouseRunsRepository implements IRunsRepository {
177178
environmentId: options.environmentId,
178179
});
179180

181+
const periodMs = options.period ? parseDuration(options.period) ?? undefined : undefined;
182+
if (periodMs) {
183+
queryBuilder.where("created_at >= fromUnixTimestamp64Milli({period: Int64})", {
184+
period: new Date(Date.now() - periodMs).getTime(),
185+
});
186+
}
187+
188+
if (options.from) {
189+
queryBuilder.where("created_at >= fromUnixTimestamp64Milli({from: Int64})", {
190+
from: options.from,
191+
});
192+
}
193+
194+
if (options.to) {
195+
queryBuilder.where("created_at <= fromUnixTimestamp64Milli({to: Int64})", { to: options.to });
196+
}
197+
180198
const [queryError, result] = await queryBuilder.execute();
181199

182200
if (queryError) {
@@ -187,8 +205,6 @@ export class ClickHouseRunsRepository implements IRunsRepository {
187205
throw new Error("No count rows returned");
188206
}
189207

190-
//todo process them
191-
192208
return {
193209
tags: result[0].tags,
194210
};

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
type ListedRun,
99
type RunListInputOptions,
1010
type RunsRepositoryOptions,
11-
TagListOptions,
11+
type TagListOptions,
1212
convertRunListInputOptionsToFilterRunsOptions,
1313
} from "./runsRepository.server";
1414

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ export type TagListOptions = {
113113
organizationId: string;
114114
projectId: string;
115115
environmentId: string;
116-
createdAfter: Date;
116+
period?: string;
117+
from?: number;
118+
to?: number;
117119
/** Performs a case insensitive contains search on the tag name */
118120
query?: string;
119121
} & OffsetPagination;
@@ -313,9 +315,20 @@ export class RunsRepository implements IRunsRepository {
313315

314316
async listTags(options: TagListOptions): Promise<TagList> {
315317
const repository = await this.#getRepository();
316-
return startActiveSpan("runsRepository.listTags", async () => {
317-
return await repository.listTags(options);
318-
});
318+
return startActiveSpan(
319+
"runsRepository.listTags",
320+
async () => {
321+
return await repository.listTags(options);
322+
},
323+
{
324+
attributes: {
325+
"repository.name": repository.name,
326+
organizationId: options.organizationId,
327+
projectId: options.projectId,
328+
environmentId: options.environmentId,
329+
},
330+
}
331+
);
319332
}
320333
}
321334

0 commit comments

Comments
 (0)