Skip to content

Commit

Permalink
Fixed region view. Closes #2648.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecao committed Apr 10, 2024
1 parent 88da20e commit 09a75ec
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/pages/api/websites/[websiteId]/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export default async (
}

if (SESSION_COLUMNS.includes(type)) {
const data = await getSessionMetrics(websiteId, column, filters, limit, offset);
const data = await getSessionMetrics(websiteId, type, filters, limit, offset);

if (type === 'language') {
const combined = {};
Expand Down
18 changes: 7 additions & 11 deletions src/queries/analytics/sessions/getSessionMetrics.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import prisma from 'lib/prisma';
import clickhouse from 'lib/clickhouse';
import { runQuery, CLICKHOUSE, PRISMA } from 'lib/db';
import { EVENT_TYPE, SESSION_COLUMNS } from 'lib/constants';
import { EVENT_TYPE, FILTER_COLUMNS, SESSION_COLUMNS } from 'lib/constants';
import { QueryFilters } from 'lib/types';

export async function getSessionMetrics(
...args: [
websiteId: string,
column: string,
filters: QueryFilters,
limit?: number,
offset?: number,
]
...args: [websiteId: string, type: string, filters: QueryFilters, limit?: number, offset?: number]
) {
return runQuery({
[PRISMA]: () => relationalQuery(...args),
Expand All @@ -21,11 +15,12 @@ export async function getSessionMetrics(

async function relationalQuery(
websiteId: string,
column: string,
type: string,
filters: QueryFilters,
limit: number = 500,
offset: number = 0,
) {
const column = FILTER_COLUMNS[type] || type;
const { parseFilters, rawQuery } = prisma;
const { filterQuery, joinSession, params } = await parseFilters(
websiteId,
Expand All @@ -34,7 +29,7 @@ async function relationalQuery(
eventType: EVENT_TYPE.pageView,
},
{
joinSession: SESSION_COLUMNS.includes(column),
joinSession: SESSION_COLUMNS.includes(type),
},
);
const includeCountry = column === 'city' || column === 'subdivision1';
Expand Down Expand Up @@ -63,11 +58,12 @@ async function relationalQuery(

async function clickhouseQuery(
websiteId: string,
column: string,
type: string,
filters: QueryFilters,
limit: number = 500,
offset: number = 0,
): Promise<{ x: string; y: number }[]> {
const column = FILTER_COLUMNS[type] || type;
const { parseFilters, rawQuery } = clickhouse;
const { filterQuery, params } = await parseFilters(websiteId, {
...filters,
Expand Down

0 comments on commit 09a75ec

Please sign in to comment.