mirror of
https://github.com/umami-software/umami.git
synced 2025-12-08 05:12:36 +01:00
Refactored query parameters.
This commit is contained in:
parent
69962eb08d
commit
89781d4847
99 changed files with 452 additions and 2273 deletions
|
|
@ -1,5 +1,5 @@
|
|||
import { getDatabase, parseFilters, rawQuery, runAnalyticsQuery } from 'lib/db';
|
||||
import { MYSQL, POSTGRESQL, CLICKHOUSE, RELATIONAL } from 'lib/constants';
|
||||
import { parseFilters, rawQuery, runAnalyticsQuery } from 'lib/db';
|
||||
import { CLICKHOUSE, RELATIONAL } from 'lib/constants';
|
||||
|
||||
export async function getPageviewParams(...args) {
|
||||
return runAnalyticsQuery({
|
||||
|
|
@ -8,8 +8,8 @@ export async function getPageviewParams(...args) {
|
|||
});
|
||||
}
|
||||
|
||||
function relationalQuery(param, website_id, start_at, end_at, column, table, filters = {}) {
|
||||
const params = [param, param, website_id, start_at, end_at];
|
||||
async function relationalQuery(website_id, start_at, end_at, column, table, filters = {}) {
|
||||
const params = [website_id, start_at, end_at];
|
||||
const { pageviewQuery, sessionQuery, eventQuery, joinSession } = parseFilters(
|
||||
table,
|
||||
column,
|
||||
|
|
@ -17,29 +17,21 @@ function relationalQuery(param, website_id, start_at, end_at, column, table, fil
|
|||
params,
|
||||
);
|
||||
|
||||
let splitFn;
|
||||
let db = getDatabase();
|
||||
if (db === MYSQL) splitFn = 'substring_index';
|
||||
if (db === POSTGRESQL) splitFn = 'split_part';
|
||||
if (!splitFn) return Promise.reject(new Error('Unknown database.'));
|
||||
|
||||
return rawQuery(
|
||||
`select * from (
|
||||
select
|
||||
url,
|
||||
IF( LENGTH(url) - LENGTH(${splitFn}(url, concat($1, '='), -1)) > 1, ${splitFn}(${splitFn}(url, concat($2, '='), -1), '&', 1), null ) param
|
||||
from
|
||||
pageview
|
||||
${joinSession}
|
||||
where
|
||||
${table}.website_id=$3 and ${table}.created_at between $4 and $5
|
||||
${pageviewQuery}
|
||||
${joinSession && sessionQuery}
|
||||
${eventQuery}
|
||||
group by 1, 2
|
||||
order by 2 desc
|
||||
) q
|
||||
where q.param <> ''`,
|
||||
`
|
||||
select url x,
|
||||
count(*) y
|
||||
from ${table}
|
||||
${joinSession}
|
||||
where ${table}.website_id=$1
|
||||
and ${table}.created_at between $2 and $3
|
||||
and ${table}.url like '%?%'
|
||||
${pageviewQuery}
|
||||
${joinSession && sessionQuery}
|
||||
${eventQuery}
|
||||
group by 1
|
||||
order by 2 desc
|
||||
`,
|
||||
params,
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue