Skip to content

Commit 83a7a84

Browse files
committed
del perf
1 parent bc4b18a commit 83a7a84

File tree

3 files changed

+59
-22
lines changed

3 files changed

+59
-22
lines changed

apps/api/src/query/builders/vitals.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,4 +327,25 @@ export const VitalsBuilders: Record<string, SimpleQueryConfig> = {
327327
customizable: true,
328328
plugins: { normalizeGeo: true, deduplicateGeo: true },
329329
},
330+
331+
performance_overview: {
332+
customSql: (websiteId: string, startDate: string, endDate: string) => ({
333+
sql: `
334+
SELECT
335+
AVG(CASE WHEN load_time > 0 THEN load_time ELSE NULL END) as avg_load_time,
336+
AVG(CASE WHEN dom_ready_time > 0 THEN dom_ready_time ELSE NULL END) as avg_dom_ready_time,
337+
AVG(CASE WHEN render_time > 0 THEN render_time ELSE NULL END) as avg_render_time
338+
FROM ${Analytics.events}
339+
WHERE
340+
client_id = {websiteId:String}
341+
AND event_name = 'screen_view'
342+
AND time >= toDateTime({startDate:String})
343+
AND time <= toDateTime(concat({endDate:String}, ' 23:59:59'))
344+
AND load_time > 0
345+
`,
346+
params: { websiteId, startDate, endDate },
347+
}),
348+
timeField: "time",
349+
customizable: false,
350+
},
330351
};

apps/api/src/routes/query.ts

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ function getAccessibleWebsites(authCtx: AuthContext) {
6767
? eq(websites.organizationId, authCtx.apiKey.organizationId)
6868
: authCtx.apiKey.userId
6969
? and(
70-
eq(websites.userId, authCtx.apiKey.userId),
71-
isNull(websites.organizationId)
72-
)
70+
eq(websites.userId, authCtx.apiKey.userId),
71+
isNull(websites.organizationId)
72+
)
7373
: eq(websites.id, "");
7474
return db
7575
.select(select)
@@ -116,12 +116,12 @@ function getTimeUnit(
116116
type ParamInput =
117117
| string
118118
| {
119-
name: string;
120-
start_date?: string;
121-
end_date?: string;
122-
granularity?: string;
123-
id?: string;
124-
};
119+
name: string;
120+
start_date?: string;
121+
end_date?: string;
122+
granularity?: string;
123+
id?: string;
124+
};
125125

126126
function parseParam(p: ParamInput) {
127127
if (typeof p === "string") {
@@ -358,17 +358,33 @@ async function runDynamicQuery(
358358
}
359359
}
360360

361+
// Build results array, separating errors from successes
362+
const allResults = prepared.map(
363+
(p) =>
364+
resultMap.get(p.id) || {
365+
parameter: p.id,
366+
success: false,
367+
error: "Unknown",
368+
data: [],
369+
}
370+
);
371+
372+
// Sort: successes first, then errors (at the bottom)
373+
const sortedResults = allResults.sort((a, b) => {
374+
const aIsError = !a.success;
375+
const bIsError = !b.success;
376+
if (!aIsError && bIsError) {
377+
return -1; // a (success) comes before b (error)
378+
}
379+
if (aIsError && !bIsError) {
380+
return 1; // b (success) comes before a (error)
381+
}
382+
return 0; // maintain original order for same type
383+
});
384+
361385
return {
362386
queryId: req.id,
363-
data: prepared.map(
364-
(p) =>
365-
resultMap.get(p.id) || {
366-
parameter: p.id,
367-
success: false,
368-
error: "Unknown",
369-
data: [],
370-
}
371-
),
387+
data: sortedResults,
372388
meta: {
373389
parameters: req.parameters,
374390
total_parameters: req.parameters.length,

apps/dashboard/components/layout/navigation/navigation-config.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,10 @@ export const websiteNavigation: NavigationSection[] = [
238238
alpha: true,
239239
gatedFeature: GATED_FEATURES.WEB_VITALS,
240240
}),
241-
createNavItem("Performance", ActivityIcon, "/performance", {
242-
rootLevel: false,
243-
tag: "deprecated",
244-
}),
241+
// createNavItem("Performance", ActivityIcon, "/performance", {
242+
// rootLevel: false,
243+
// tag: "deprecated",
244+
// }),
245245
createNavItem("Geographic", MapPinIcon, "/map", {
246246
rootLevel: false,
247247
gatedFeature: GATED_FEATURES.GEOGRAPHIC,

0 commit comments

Comments
 (0)