mirror of
https://github.com/kremalicious/umami.git
synced 2025-02-14 21:10:34 +01:00
Added limit to metrics queries.
This commit is contained in:
parent
a851ebf124
commit
907685b96e
@ -144,7 +144,6 @@ export default function WebsiteExpandedView({
|
||||
<DetailsComponent
|
||||
websiteId={websiteId}
|
||||
websiteDomain={websiteDomain}
|
||||
limit={false}
|
||||
animate={false}
|
||||
virtualize={true}
|
||||
itemCount={25}
|
||||
|
@ -77,6 +77,7 @@ export function MetricsTable({
|
||||
type,
|
||||
startAt: +startDate,
|
||||
endAt: +endDate,
|
||||
limit,
|
||||
...filters,
|
||||
});
|
||||
|
||||
|
@ -135,7 +135,11 @@ function normalizeFilters(filters = {}) {
|
||||
}, {});
|
||||
}
|
||||
|
||||
async function parseFilters(websiteId, filters: QueryFilters = {}, options: QueryOptions = {}) {
|
||||
async function parseFilters(
|
||||
websiteId: string,
|
||||
filters: QueryFilters = {},
|
||||
options: QueryOptions = {},
|
||||
) {
|
||||
const website = await loadWebsite(websiteId);
|
||||
|
||||
return {
|
||||
|
@ -206,6 +206,7 @@ export interface QueryFilters {
|
||||
export interface QueryOptions {
|
||||
joinSession?: boolean;
|
||||
columns?: { [key: string]: string };
|
||||
limit?: number;
|
||||
}
|
||||
|
||||
export interface RealtimeData {
|
||||
|
@ -25,6 +25,7 @@ export interface WebsiteMetricsRequestQuery {
|
||||
city?: string;
|
||||
language?: string;
|
||||
event?: string;
|
||||
limit?: number;
|
||||
}
|
||||
|
||||
const schema = {
|
||||
@ -45,6 +46,7 @@ const schema = {
|
||||
city: yup.string(),
|
||||
language: yup.string(),
|
||||
event: yup.string(),
|
||||
limit: yup.number(),
|
||||
}),
|
||||
};
|
||||
|
||||
@ -71,6 +73,7 @@ export default async (
|
||||
city,
|
||||
language,
|
||||
event,
|
||||
limit,
|
||||
} = req.query;
|
||||
|
||||
if (req.method === 'GET') {
|
||||
@ -100,7 +103,7 @@ export default async (
|
||||
const column = FILTER_COLUMNS[type] || type;
|
||||
|
||||
if (SESSION_COLUMNS.includes(type)) {
|
||||
const data = await getSessionMetrics(websiteId, column, filters);
|
||||
const data = await getSessionMetrics(websiteId, column, filters, limit);
|
||||
|
||||
if (type === 'language') {
|
||||
const combined = {};
|
||||
@ -122,7 +125,7 @@ export default async (
|
||||
}
|
||||
|
||||
if (EVENT_COLUMNS.includes(type)) {
|
||||
const data = await getPageviewMetrics(websiteId, column, filters);
|
||||
const data = await getPageviewMetrics(websiteId, column, filters, limit);
|
||||
|
||||
return ok(res, data);
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import { EVENT_TYPE, SESSION_COLUMNS } from 'lib/constants';
|
||||
import { QueryFilters } from 'lib/types';
|
||||
|
||||
export async function getPageviewMetrics(
|
||||
...args: [websiteId: string, columns: string, filters: QueryFilters]
|
||||
...args: [websiteId: string, columns: string, filters: QueryFilters, limit?: number]
|
||||
) {
|
||||
return runQuery({
|
||||
[PRISMA]: () => relationalQuery(...args),
|
||||
@ -13,7 +13,12 @@ export async function getPageviewMetrics(
|
||||
});
|
||||
}
|
||||
|
||||
async function relationalQuery(websiteId: string, column: string, filters: QueryFilters) {
|
||||
async function relationalQuery(
|
||||
websiteId: string,
|
||||
column: string,
|
||||
filters: QueryFilters,
|
||||
limit: number = 100,
|
||||
) {
|
||||
const { rawQuery, parseFilters } = prisma;
|
||||
const { filterQuery, joinSession, params } = await parseFilters(
|
||||
websiteId,
|
||||
@ -42,7 +47,7 @@ async function relationalQuery(websiteId: string, column: string, filters: Query
|
||||
${filterQuery}
|
||||
group by 1
|
||||
order by 2 desc
|
||||
limit 100
|
||||
limit ${limit}
|
||||
`,
|
||||
params,
|
||||
);
|
||||
@ -52,6 +57,7 @@ async function clickhouseQuery(
|
||||
websiteId: string,
|
||||
column: string,
|
||||
filters: QueryFilters,
|
||||
limit: number = 100,
|
||||
): Promise<{ x: string; y: number }[]> {
|
||||
const { rawQuery, parseFilters } = clickhouse;
|
||||
const { filterQuery, params } = await parseFilters(websiteId, {
|
||||
@ -75,7 +81,7 @@ async function clickhouseQuery(
|
||||
${filterQuery}
|
||||
group by x
|
||||
order by y desc
|
||||
limit 100
|
||||
limit ${limit}
|
||||
`,
|
||||
params,
|
||||
).then(a => {
|
||||
|
@ -5,7 +5,7 @@ import { EVENT_TYPE, SESSION_COLUMNS } from 'lib/constants';
|
||||
import { QueryFilters } from 'lib/types';
|
||||
|
||||
export async function getSessionMetrics(
|
||||
...args: [websiteId: string, column: string, filters: QueryFilters]
|
||||
...args: [websiteId: string, column: string, filters: QueryFilters, limit?: number]
|
||||
) {
|
||||
return runQuery({
|
||||
[PRISMA]: () => relationalQuery(...args),
|
||||
@ -13,7 +13,12 @@ export async function getSessionMetrics(
|
||||
});
|
||||
}
|
||||
|
||||
async function relationalQuery(websiteId: string, column: string, filters: QueryFilters) {
|
||||
async function relationalQuery(
|
||||
websiteId: string,
|
||||
column: string,
|
||||
filters: QueryFilters,
|
||||
limit: number = 100,
|
||||
) {
|
||||
const { parseFilters, rawQuery } = prisma;
|
||||
const { filterQuery, joinSession, params } = await parseFilters(
|
||||
websiteId,
|
||||
@ -42,7 +47,7 @@ async function relationalQuery(websiteId: string, column: string, filters: Query
|
||||
group by 1
|
||||
${includeCountry ? ', 3' : ''}
|
||||
order by 2 desc
|
||||
limit 100`,
|
||||
limit ${limit}`,
|
||||
params,
|
||||
);
|
||||
}
|
||||
@ -51,6 +56,7 @@ async function clickhouseQuery(
|
||||
websiteId: string,
|
||||
column: string,
|
||||
filters: QueryFilters,
|
||||
limit: number = 100,
|
||||
): Promise<{ x: string; y: number }[]> {
|
||||
const { parseFilters, rawQuery } = clickhouse;
|
||||
const { filterQuery, params } = await parseFilters(websiteId, {
|
||||
@ -73,7 +79,7 @@ async function clickhouseQuery(
|
||||
group by x
|
||||
${includeCountry ? ', country' : ''}
|
||||
order by y desc
|
||||
limit 100
|
||||
limit ${limit}
|
||||
`,
|
||||
params,
|
||||
).then(a => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user