Skip to content

Commit fc74bf7

Browse files
committed
feat: remove postgres query from workspace stat
1 parent c3528fd commit fc74bf7

1 file changed

Lines changed: 2 additions & 28 deletions

File tree

webapps/ee-api/pages/api/report/workspace-stat.ts

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { NextApiRequest, NextApiResponse } from "next";
2-
import { getLog, namedParameters, SqlQueryParameters, unrollParams } from "juava";
2+
import { namedParameters, SqlQueryParameters, unrollParams } from "juava";
33
import { withErrorHandler } from "../../../lib/error-handler";
44
import { auth } from "../../../lib/auth";
55
import { clickhouse, pg } from "../../../lib/services";
@@ -39,28 +39,6 @@ function isoDateTOClickhouse(date: ISODate): string {
3939
return date.replace("T", " ").replace("Z", "").split(".")[0];
4040
}
4141

42-
async function getPostgresPart({ granularity, start, end, workspaceId }: ReportParams): Promise<WorkspaceReportRow[]> {
43-
const sql = `select
44-
obj."workspaceId" as "workspaceId",
45-
date_trunc(:granularity, (m.timestamp::TIMESTAMPTZ)) as period,
46-
sum(m.value) as events
47-
from newjitsuee.bulker_metrics m
48-
left join newjitsu."ConfigurationObjectLink" obj
49-
on obj."id" = m."destinationId"
50-
where m.metric_name = 'bulkerapp_ingest_messages' and m.status = 'success' and m.timestamp <= '2023-07-28T00:00:00Z' and ${
51-
workspaceId ? 'obj."workspaceId" = :workspaceId and' : ""
52-
} date_trunc(:granularity, "timestamp") >= date_trunc(:granularity, :start::timestamp) and
53-
date_trunc(:granularity, "timestamp") <= date_trunc(:granularity, :end::timestamp)
54-
group by period, "workspaceId"
55-
order by period, "workspaceId" desc;;
56-
`;
57-
const params = removeUndefined({ start, end, granularity, workspaceId });
58-
const { query, values } = namedParameters(sql, params);
59-
return await pg.query({ text: query, values }).then(res => {
60-
return res.rows;
61-
});
62-
}
63-
6442
async function getClickhousePart({
6543
granularity,
6644
start,
@@ -136,11 +114,7 @@ export async function buildWorkspaceReport(
136114
granularity: "day",
137115
workspaceId: string | undefined
138116
): Promise<WorkspaceReportRow[]> {
139-
const [pgRes, chRes] = await Promise.all([
140-
getPostgresPart({ start, end, granularity, workspaceId }),
141-
getClickhousePart({ start, end, granularity, workspaceId }),
142-
]);
143-
return [...pgRes.map(s => ({ ...s, src: "pg" })), ...chRes.map(s => ({ ...s, src: "ch" }))];
117+
return (await getClickhousePart({ start, end, granularity, workspaceId })).map(s => ({ ...s, src: "ch" }));
144118
}
145119

146120
async function extend(reportResult: WorkspaceReportRow[]): Promise<ExtendedWorkspaceReportRow[]> {

0 commit comments

Comments
 (0)