diff --git a/src/queries/analytics/reports/getJourney.ts b/src/queries/analytics/reports/getJourney.ts index 24879a86..34d166a5 100644 --- a/src/queries/analytics/reports/getJourney.ts +++ b/src/queries/analytics/reports/getJourney.ts @@ -43,7 +43,7 @@ async function relationalQuery( ): Promise { const { startDate, endDate, steps, startStep, endStep } = filters; const { rawQuery } = prisma; - const { sequenceQuery, startStepQuery, endStepQuery, finalSelectQuery, params } = getJourneyQuery( + const { sequenceQuery, startStepQuery, endStepQuery, params } = getJourneyQuery( steps, startStep, endStep, @@ -57,14 +57,12 @@ async function relationalQuery( sequenceQuery: string; startStepQuery: string; endStepQuery: string; - finalSelectQuery: string; params: { [key: string]: string }; } { const params = {}; let sequenceQuery = ''; let startStepQuery = ''; let endStepQuery = ''; - let finalSelectQuery = ''; // create sequence query let selectQuery = ''; @@ -106,18 +104,10 @@ async function relationalQuery( params['endStep'] = endStep; } - // create final select query - for (let i = 1; i < steps; i++) { - finalSelectQuery += `\nCASE WHEN e${i} IS NOT NULL and e${ - i + 1 - } IS NULL THEN 'dropped off' ELSE e${i + 1} END AS e${i + 1},`; - } - return { sequenceQuery, startStepQuery, endStepQuery, - finalSelectQuery, params, }; } @@ -134,9 +124,7 @@ async function relationalQuery( where website_id = {{websiteId::uuid}} and created_at between {{startDate}} and {{endDate}}), ${sequenceQuery} - select e1, - ${finalSelectQuery} - count + select * from sequences where 1 = 1 ${startStepQuery} @@ -165,7 +153,7 @@ async function clickhouseQuery( ): Promise { const { startDate, endDate, steps, startStep, endStep } = filters; const { rawQuery } = clickhouse; - const { sequenceQuery, startStepQuery, endStepQuery, finalSelectQuery, params } = getJourneyQuery( + const { sequenceQuery, startStepQuery, endStepQuery, params } = getJourneyQuery( steps, startStep, endStep, @@ -179,14 +167,12 @@ async function clickhouseQuery( sequenceQuery: string; startStepQuery: string; endStepQuery: string; - finalSelectQuery: string; params: { [key: string]: string }; } { const params = {}; let sequenceQuery = ''; let startStepQuery = ''; let endStepQuery = ''; - let finalSelectQuery = ''; // create sequence query let selectQuery = ''; @@ -221,25 +207,17 @@ async function clickhouseQuery( if (endStep) { for (let i = 1; i < steps; i++) { const startQuery = i === 1 ? 'and (' : '\nor '; - endStepQuery += `${startQuery}(e${i} = {endStep:String} and e${i + 1} = 'dropped off') `; + endStepQuery += `${startQuery}(e${i} = {endStep:String} and e${i + 1} is null) `; } endStepQuery += `\nor (e${steps} = {endStep:String}))`; params['endStep'] = endStep; } - // create final select query - for (let i = 1; i < steps; i++) { - finalSelectQuery += `\nCASE WHEN e${i} IS NOT NULL and e${ - i + 1 - } IS NULL THEN 'dropped off' ELSE e${i + 1} END AS e${i + 1},`; - } - return { sequenceQuery, startStepQuery, endStepQuery, - finalSelectQuery, params, }; } @@ -255,9 +233,7 @@ async function clickhouseQuery( where website_id = {websiteId:UUID} and created_at between {startDate:DateTime64} and {endDate:DateTime64}), ${sequenceQuery} - select e1, - ${finalSelectQuery} - count + select * from sequences where 1 = 1 ${startStepQuery}