Show active visitor count.

This commit is contained in:
Mike Cao committed 2020-08-18 00:51:32 -07:00
1 parent 9f6e17b986
commit b96cb0d975
14 files changed
+158 -35

No files matched your search

+14
View File
@@ -1,5 +1,6 @@
import moment from 'moment-timezone';
import prisma, { runQuery } from 'lib/db';
import { subMinutes } from 'date-fns';
const POSTGRESQL = 'postgresql';
const MYSQL = 'mysql';
@@ -366,3 +367,16 @@ export function getRankings(website_id, start_at, end_at, type, table) {
return Promise.resolve([]);
}
export function getActiveVisitors(website_id) {
return prisma.$queryRaw(
`
select count(distinct session_id) x
from pageview
where website_id=$1
and created_at >= $2
`,
website_id,
subMinutes(new Date(), 5),
);
}