MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / fetch

Function fetch

packages/db/src/engine/fetch.ts:13–148  ·  view source on GitHub ↗
(plan: Plan)

Source from the content-addressed store, hash-verified

11 * This handles breakdown expansion automatically via groupByLabels
12 */
13export async function fetch(plan: Plan): Promise<ConcreteSeries[]> {
14 const results: ConcreteSeries[] = [];
15
16 // Process each event definition
17 for (let i = 0; i < plan.definitions.length; i++) {
18 const definition = plan.definitions[i]!;
19
20 if (definition.type !== 'event') {
21 // Skip formulas - they'll be handled in compute stage
22 continue;
23 }
24
25 const event = definition as typeof definition & { type: 'event' };
26
27 // Find the corresponding concrete series placeholder
28 const placeholder = plan.concreteSeries.find(
29 (cs) => cs.definitionId === definition.id,
30 );
31
32 if (!placeholder) {
33 continue;
34 }
35
36 // Build query input
37 const queryInput: IGetChartDataInput = {
38 event: {
39 id: event.id,
40 name: event.name,
41 segment: event.segment,
42 filters: event.filters,
43 displayName: event.displayName,
44 property: event.property,
45 },
46 projectId: plan.input.projectId,
47 startDate: plan.input.startDate,
48 endDate: plan.input.endDate,
49 breakdowns: plan.input.breakdowns,
50 interval: plan.input.interval,
51 chartType: plan.input.chartType,
52 metric: plan.input.metric,
53 previous: plan.input.previous ?? false,
54 limit: plan.input.limit,
55 offset: plan.input.offset,
56 };
57
58 // Execute query
59 let queryResult = await chQuery<ISerieDataItem>(
60 await getChartSql({ ...queryInput, timezone: plan.timezone }),
61 {
62 session_timezone: plan.timezone,
63 },
64 );
65
66 // Fallback: if no results with breakdowns, try without breakdowns
67 if (queryResult.length === 0 && plan.input.breakdowns.length > 0) {
68 queryResult = await chQuery<ISerieDataItem>(
69 await getChartSql({
70 ...queryInput,

Callers 15

executeChartFunction · 0.90
parseRemoteFileMethod · 0.50
streamProfilesMethod · 0.50
fetchExportWithRetryMethod · 0.50
verifyPasswordStrengthFunction · 0.50
handleApiRouteFunction · 0.50
handleApiRouteFunction · 0.50
handleScriptProxyRouteFunction · 0.50
postMethod · 0.50
sendSlackNotificationFunction · 0.50
sendDiscordNotificationFunction · 0.50

Calls 5

getChartSqlFunction · 0.90
groupByLabelsFunction · 0.90
joinMethod · 0.80
pushMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected