Skip to content

armgit / umami

Public Imported from GitHub
0

Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.

Add table alias to filterQuery. Closed  #3869

Francis Cao3072f02f1bc2
diff --git a/src/lib/prisma.ts b/src/lib/prisma.ts
index 64cb870fd..bfd007d1b 100644
--- a/src/lib/prisma.ts
+++ b/src/lib/prisma.ts
@@ -74,15 +74,21 @@ function getSearchSQL(column: string, param: string = 'search'): string {
function mapFilter(column: string, operator: string, name: string, type: string = '') {
const value = `{{${name}${type ? `::${type}` : ''}}}`;
+ if (name.startsWith('cohort_')) {
+ name = name.slice('cohort_'.length);
+ }
+
+ const table = SESSION_COLUMNS.includes(name) ? 'session' : 'website_event';
+
switch (operator) {
case OPERATORS.equals:
- return `${column} = ${value}`;
+ return `${table}.${column} = ${value}`;
case OPERATORS.notEquals:
- return `${column} != ${value}`;
+ return `${table}.${column} != ${value}`;
case OPERATORS.contains:
- return `${column} ilike ${value}`;
+ return `${table}.${column} ilike ${value}`;
case OPERATORS.doesNotContain:
- return `${column} not ilike ${value}`;
+ return `${table}.${column} not ilike ${value}`;
default:
return '';
}
diff --git a/src/queries/sql/reports/getRevenue.ts b/src/queries/sql/reports/getRevenue.ts
index 19b75d429..2a4604fec 100644
--- a/src/queries/sql/reports/getRevenue.ts
+++ b/src/queries/sql/reports/getRevenue.ts
@@ -41,14 +41,15 @@ async function relationalQuery(
currency,
});
- const joinQuery = filterQuery
- ? `join website_event
+ const joinQuery =
+ filterQuery || cohortQuery
+ ? `join website_event
on website_event.website_id = revenue.website_id
and website_event.session_id = revenue.session_id
and website_event.event_id = revenue.event_id
and website_event.website_id = {{websiteId::uuid}}
and website_event.created_at between {{startDate}} and {{endDate}}`
- : '';
+ : '';
const chart = await rawQuery(
`