roll back id adds

This commit is contained in:
Brian Cao 2022-10-10 17:01:48 -07:00
parent ec6454aead
commit 4073d57e64
10 changed files with 14 additions and 22 deletions

View File

@ -60,8 +60,8 @@ function getDateFormat(date) {
return `'${dateFormat(date, 'UTC:yyyy-mm-dd HH:MM:ss')}'`;
}
function getCommaSeparatedStringFormat(data, column) {
return data.map(obj => `'${obj[column]}'`).join(',');
function getCommaSeparatedStringFormat(data) {
return data.map(a => `'${a}'`).join(',');
}
function getBetweenDates(field, start_at, end_at) {

View File

@ -14,9 +14,8 @@ export default async (req, res) => {
const { id } = req.query;
const websiteId = +id;
const website_uuid = id;
const result = await getActiveVisitors(websiteId, website_uuid);
const result = await getActiveVisitors(websiteId);
return ok(res, result);
}

View File

@ -21,11 +21,10 @@ export default async (req, res) => {
}
const websiteId = +id;
const website_uuid = id;
const startDate = new Date(+start_at);
const endDate = new Date(+end_at);
const events = await getEventMetrics(websiteId, website_uuid, startDate, endDate, tz, unit, {
const events = await getEventMetrics(websiteId, startDate, endDate, tz, unit, {
url,
eventName: event_name,
});

View File

@ -44,7 +44,6 @@ export default async (req, res) => {
const { id, type, start_at, end_at, url, referrer, os, browser, device, country } = req.query;
const websiteId = +id;
const website_uuid = id;
const startDate = new Date(+start_at);
const endDate = new Date(+end_at);
@ -107,7 +106,7 @@ export default async (req, res) => {
query: type === 'query' && table !== 'event' ? true : undefined,
};
const data = await getPageviewMetrics(websiteId, website_uuid, {
const data = await getPageviewMetrics(websiteId, {
startDate,
endDate,
column,

View File

@ -18,7 +18,6 @@ export default async (req, res) => {
req.query;
const websiteId = +id;
const website_uuid = id;
const startDate = new Date(+start_at);
const endDate = new Date(+end_at);
@ -27,7 +26,7 @@ export default async (req, res) => {
}
const [pageviews, sessions] = await Promise.all([
getPageviewStats(websiteId, website_uuid, {
getPageviewStats(websiteId, {
start_at: startDate,
end_at: endDate,
timezone: tz,
@ -42,7 +41,7 @@ export default async (req, res) => {
country,
},
}),
getPageviewStats(websiteId, website_uuid, {
getPageviewStats(websiteId, {
start_at: startDate,
end_at: endDate,
timezone: tz,

View File

@ -1,4 +1,4 @@
import { getWebsiteStats, getWebsiteById } from 'queries';
import { getWebsiteStats } from 'queries';
import { methodNotAllowed, ok, unauthorized } from 'next-basics';
import { allowQuery } from 'lib/auth';
import { useCors } from 'lib/middleware';
@ -14,7 +14,6 @@ export default async (req, res) => {
const { website_id, start_at, end_at, url, referrer, os, browser, device, country } = req.query;
const websiteId = +website_id;
let websiteUuid = (await getWebsiteById(websiteId)).websiteUuid;
const startDate = new Date(+start_at);
const endDate = new Date(+end_at);
@ -22,7 +21,7 @@ export default async (req, res) => {
const prevStartDate = new Date(+start_at - distance);
const prevEndDate = new Date(+end_at - distance);
const metrics = await getWebsiteStats(websiteUuid, {
const metrics = await getWebsiteStats(websiteId, {
start_at: startDate,
end_at: endDate,
filters: {
@ -34,7 +33,7 @@ export default async (req, res) => {
country,
},
});
const prevPeriod = await getWebsiteStats(websiteUuid, {
const prevPeriod = await getWebsiteStats(websiteId, {
start_at: prevStartDate,
end_at: prevEndDate,
filters: {

View File

@ -37,7 +37,6 @@ async function relationalQuery(
async function clickhouseQuery(
websiteId,
website_uuid,
start_at,
end_at,
timezone = 'UTC',

View File

@ -39,7 +39,7 @@ function clickhouseQuery(websites, start_at) {
where event_name != ''
and ${
websites && websites.length > 0
? `website_id in (${getCommaSeparatedStringFormat(websites, websites.website_uuid)})`
? `website_id in (${getCommaSeparatedStringFormat(websites)})`
: '0 = 0'
}
and created_at >= ${getDateFormat(start_at)}`,

View File

@ -34,15 +34,13 @@ async function relationalQuery(websiteId, { sessionId, url, eventName, eventData
async function clickhouseQuery(
websiteId,
{ session: { country, sessionUuid, ...sessionArgs }, eventUuid, url, eventName, eventData },
website_uuid,
) {
const { getDateFormat, sendMessage } = kafka;
const params = {
session_uuid: sessionUuid,
event_uuid: eventUuid,
session_id: sessionUuid,
event_id: eventUuid,
website_id: websiteId,
website_uuid,
created_at: getDateFormat(new Date()),
url: url?.substring(0, URL_LENGTH),
event_name: eventName?.substring(0, EVENT_NAME_LENGTH),

View File

@ -37,7 +37,7 @@ async function clickhouseQuery(websites, start_at) {
where event_name = ''
and ${
websites && websites.length > 0
? `website_id in (${getCommaSeparatedStringFormat(websites, websites.website_uuid)})`
? `website_id in (${getCommaSeparatedStringFormat(websites)})`
: '0 = 0'
}
and created_at >= ${clickhouse.getDateFormat(start_at)}`,