mirror of
https://github.com/umami-software/umami.git
synced 2026-02-11 16:17:13 +01:00
Refactored query parameter handling.
This commit is contained in:
parent
157862834d
commit
7148f66d1a
17 changed files with 260 additions and 469 deletions
|
|
@ -1,7 +1,10 @@
|
|||
import prisma from '@umami/prisma-client';
|
||||
import moment from 'moment-timezone';
|
||||
import { MYSQL, POSTGRESQL, getDatabaseType } from 'lib/db';
|
||||
import { FILTER_COLUMNS, SESSION_COLUMNS } from './constants';
|
||||
import { FILTER_COLUMNS, IGNORED_FILTERS, SESSION_COLUMNS } from './constants';
|
||||
import { loadWebsite } from './load';
|
||||
import { maxDate } from './date';
|
||||
import { QueryFilters } from './types';
|
||||
|
||||
const MYSQL_DATE_FORMATS = {
|
||||
minute: '%Y-%m-%d %H:%i:00',
|
||||
|
|
@ -68,14 +71,14 @@ function getFilterQuery(filters = {}): string {
|
|||
const query = Object.keys(filters).reduce((arr, key) => {
|
||||
const filter = filters[key];
|
||||
|
||||
if (filter !== undefined) {
|
||||
if (filter !== undefined && !IGNORED_FILTERS.includes(key)) {
|
||||
const column = FILTER_COLUMNS[key] || key;
|
||||
arr.push(`and ${column}={{${key}}}`);
|
||||
}
|
||||
|
||||
if (key === 'referrer') {
|
||||
arr.push(
|
||||
'and (website_event.referrer_domain != {{domain}} or website_event.referrer_domain is null)',
|
||||
'and (website_event.referrer_domain != {{websiteDomain}} or website_event.referrer_domain is null)',
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -85,12 +88,20 @@ function getFilterQuery(filters = {}): string {
|
|||
return query.join('\n');
|
||||
}
|
||||
|
||||
function parseFilters(filters: { [key: string]: any } = {}) {
|
||||
async function parseFilters(websiteId, filters: QueryFilters & { [key: string]: any } = {}) {
|
||||
const website = await loadWebsite(websiteId);
|
||||
|
||||
return {
|
||||
joinSession: Object.keys(filters).find(key => SESSION_COLUMNS[key])
|
||||
? `inner join session on website_event.session_id = session.session_id`
|
||||
: '',
|
||||
filterQuery: getFilterQuery(filters),
|
||||
params: {
|
||||
...filters,
|
||||
websiteId,
|
||||
startDate: maxDate(filters.startDate, website.resetAt),
|
||||
websiteDomain: website.domain,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue