From fbe35f4c97a3fd44b9bff5725166edde0b8ef3e5 Mon Sep 17 00:00:00 2001 From: Francis Cao Date: Mon, 27 Mar 2023 12:11:06 -0700 Subject: [PATCH] fixed relational query to get reset_at --- queries/analytics/event/getEventMetrics.ts | 3 ++- queries/analytics/eventData/getEventData.ts | 3 ++- queries/analytics/pageview/getPageviewMetrics.ts | 3 ++- queries/analytics/pageview/getPageviewStats.ts | 3 ++- queries/analytics/session/getSessionMetrics.ts | 3 ++- queries/analytics/stats/getWebsiteStats.ts | 3 ++- 6 files changed, 12 insertions(+), 6 deletions(-) diff --git a/queries/analytics/event/getEventMetrics.ts b/queries/analytics/event/getEventMetrics.ts index 35eda8f6..f69d9bb1 100644 --- a/queries/analytics/event/getEventMetrics.ts +++ b/queries/analytics/event/getEventMetrics.ts @@ -4,6 +4,7 @@ import { runQuery, CLICKHOUSE, PRISMA } from 'lib/db'; import cache from 'lib/cache'; import { WebsiteEventMetric } from 'lib/types'; import { EVENT_TYPE } from 'lib/constants'; +import { getWebsite } from 'queries'; export async function getEventMetrics( ...args: [ @@ -46,7 +47,7 @@ async function relationalQuery( }, ) { const { toUuid, rawQuery, getDateQuery, getFilterQuery } = prisma; - const website = await cache.fetchWebsite(websiteId); + const website = await getWebsite({ id: websiteId }); const resetDate = website?.resetAt || website?.createdAt; const params: any = [websiteId, resetDate, startDate, endDate]; diff --git a/queries/analytics/eventData/getEventData.ts b/queries/analytics/eventData/getEventData.ts index f8e2febb..cd44d29a 100644 --- a/queries/analytics/eventData/getEventData.ts +++ b/queries/analytics/eventData/getEventData.ts @@ -3,6 +3,7 @@ import clickhouse from 'lib/clickhouse'; import { CLICKHOUSE, PRISMA, runQuery } from 'lib/db'; import prisma from 'lib/prisma'; import { WebsiteEventDataMetric } from 'lib/types'; +import { getWebsite } from 'queries'; export async function getEventData( ...args: [ @@ -48,7 +49,7 @@ async function relationalQuery( ) { const { startDate, endDate, timeSeries, eventName, urlPath, filters } = data; const { toUuid, rawQuery, getEventDataFilterQuery, getDateQuery } = prisma; - const website = await cache.fetchWebsite(websiteId); + const website = await getWebsite({ id: websiteId }); const resetDate = website?.resetAt || website?.createdAt; const params: any = [websiteId, resetDate, startDate, endDate, eventName || '']; diff --git a/queries/analytics/pageview/getPageviewMetrics.ts b/queries/analytics/pageview/getPageviewMetrics.ts index 09524047..53464591 100644 --- a/queries/analytics/pageview/getPageviewMetrics.ts +++ b/queries/analytics/pageview/getPageviewMetrics.ts @@ -4,6 +4,7 @@ import { runQuery, CLICKHOUSE, PRISMA } from 'lib/db'; import cache from 'lib/cache'; import { Prisma } from '@prisma/client'; import { EVENT_TYPE } from 'lib/constants'; +import { getWebsite } from 'queries'; export async function getPageviewMetrics( ...args: [ @@ -35,7 +36,7 @@ async function relationalQuery( ) { const { startDate, endDate, column, filters = {}, type } = data; const { rawQuery, parseFilters, toUuid } = prisma; - const website = await cache.fetchWebsite(websiteId); + const website = await getWebsite({ id: websiteId }); const resetDate = website?.resetAt || website?.createdAt; const params: any = [ websiteId, diff --git a/queries/analytics/pageview/getPageviewStats.ts b/queries/analytics/pageview/getPageviewStats.ts index c6197312..894f512b 100644 --- a/queries/analytics/pageview/getPageviewStats.ts +++ b/queries/analytics/pageview/getPageviewStats.ts @@ -3,6 +3,7 @@ import clickhouse from 'lib/clickhouse'; import { CLICKHOUSE, PRISMA, runQuery } from 'lib/db'; import prisma from 'lib/prisma'; import { EVENT_TYPE } from 'lib/constants'; +import { getWebsite } from 'queries'; export async function getPageviewStats( ...args: [ @@ -46,7 +47,7 @@ async function relationalQuery( sessionKey = 'session_id', } = data; const { toUuid, getDateQuery, parseFilters, rawQuery } = prisma; - const website = await cache.fetchWebsite(websiteId); + const website = await getWebsite({ id: websiteId }); const resetDate = website?.resetAt || website?.createdAt; const params: any = [websiteId, resetDate, startDate, endDate]; const { filterQuery, joinSession } = parseFilters(filters, params); diff --git a/queries/analytics/session/getSessionMetrics.ts b/queries/analytics/session/getSessionMetrics.ts index 073f93f6..dc391d84 100644 --- a/queries/analytics/session/getSessionMetrics.ts +++ b/queries/analytics/session/getSessionMetrics.ts @@ -3,6 +3,7 @@ import clickhouse from 'lib/clickhouse'; import { runQuery, CLICKHOUSE, PRISMA } from 'lib/db'; import cache from 'lib/cache'; import { EVENT_TYPE } from 'lib/constants'; +import { getWebsite } from 'queries'; export async function getSessionMetrics( ...args: [ @@ -20,7 +21,7 @@ async function relationalQuery( websiteId: string, data: { startDate: Date; endDate: Date; field: string; filters: object }, ) { - const website = await cache.fetchWebsite(websiteId); + const website = await getWebsite({ id: websiteId }); const resetDate = website?.resetAt || website?.createdAt; const { startDate, endDate, field, filters = {} } = data; const { toUuid, parseFilters, rawQuery } = prisma; diff --git a/queries/analytics/stats/getWebsiteStats.ts b/queries/analytics/stats/getWebsiteStats.ts index d11de565..39a89cbc 100644 --- a/queries/analytics/stats/getWebsiteStats.ts +++ b/queries/analytics/stats/getWebsiteStats.ts @@ -3,6 +3,7 @@ import clickhouse from 'lib/clickhouse'; import { runQuery, CLICKHOUSE, PRISMA } from 'lib/db'; import cache from 'lib/cache'; import { EVENT_TYPE } from 'lib/constants'; +import { getWebsite } from 'queries'; export async function getWebsiteStats( ...args: [websiteId: string, data: { startDate: Date; endDate: Date; filters: object }] @@ -19,7 +20,7 @@ async function relationalQuery( ) { const { startDate, endDate, filters = {} } = data; const { toUuid, getDateQuery, getTimestampInterval, parseFilters, rawQuery } = prisma; - const website = await cache.fetchWebsite(websiteId); + const website = await getWebsite({ id: websiteId }); const resetDate = website?.resetAt || website?.createdAt; const params: any = [websiteId, resetDate, startDate, endDate]; const { filterQuery, joinSession } = parseFilters(filters, params);