Minor tweaks.

This commit is contained in:
Mike Cao 2020-07-20 19:24:33 -07:00
parent 132bbcbe0d
commit 0edf87941a
6 changed files with 24 additions and 22 deletions

View File

@ -1,6 +1,8 @@
import { PrismaClient } from '@prisma/client'; import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient(); const prisma = new PrismaClient({
log: [process.env.NODE_ENV !== 'production' && 'query'],
});
export async function runQuery(query) { export async function runQuery(query) {
return query return query

View File

@ -1,7 +1,7 @@
import { getWebsite, getSession, createSession } from 'lib/db'; import { getWebsite, getSession, createSession } from 'lib/db';
import { getCountry, getDevice, getIpAddress, hash, isValidSession } from 'lib/utils'; import { getCountry, getDevice, getIpAddress, hash, isValidSession } from 'lib/utils';
export default async function checkSession(req) { export default async req => {
const { payload } = req.body; const { payload } = req.body;
const { session } = payload; const { session } = payload;
@ -19,7 +19,7 @@ export default async function checkSession(req) {
if (website) { if (website) {
const { website_id } = website; const { website_id } = website;
const session_uuid = hash(`${website_id}${hostname}${ip}${userAgent}${os}`); const session_uuid = hash(website_id, hostname, ip, userAgent, os);
let session = await getSession(session_uuid); let session = await getSession(session_uuid);
@ -46,4 +46,4 @@ export default async function checkSession(req) {
].join(':'); ].join(':');
} }
} }
} };

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,5 @@
import 'dotenv/config'; import 'dotenv/config';
import buble from '@rollup/plugin-buble'; import buble from '@rollup/plugin-buble';
import replace from '@rollup/plugin-replace';
import { nodeResolve } from '@rollup/plugin-node-resolve'; import { nodeResolve } from '@rollup/plugin-node-resolve';
import { terser } from 'rollup-plugin-terser'; import { terser } from 'rollup-plugin-terser';
@ -10,12 +9,5 @@ export default {
file: 'public/umami.js', file: 'public/umami.js',
format: 'iife', format: 'iife',
}, },
plugins: [ plugins: [nodeResolve(), buble(), terser({ compress: { evaluate: false } })],
replace({
'process.env.UMAMI_URL': JSON.stringify(process.env.UMAMI_URL),
}),
nodeResolve(),
buble(),
terser({ compress: { evaluate: false } }),
],
}; };

View File

@ -73,7 +73,9 @@ import 'unfetch/polyfill';
const orig = history[type]; const orig = history[type];
return (state, title, url) => { return (state, title, url) => {
const args = [state, title, url]; const args = [state, title, url];
cb.apply(null, args); cb.apply(null, args);
return orig.apply(history, args); return orig.apply(history, args);
}; };
}; };
@ -85,7 +87,7 @@ import 'unfetch/polyfill';
const removeEvents = () => { const removeEvents = () => {
listeners.forEach(([element, type, listener]) => { listeners.forEach(([element, type, listener]) => {
element.removeEventListener(type, listener, true); element && element.removeEventListener(type, listener, true);
}); });
listeners.length = 0; listeners.length = 0;
}; };
@ -93,13 +95,12 @@ import 'unfetch/polyfill';
const loadEvents = () => { const loadEvents = () => {
document.querySelectorAll("[class*='umami--']").forEach(element => { document.querySelectorAll("[class*='umami--']").forEach(element => {
element.className.split(' ').forEach(className => { element.className.split(' ').forEach(className => {
if (/^umami--/.test(className)) { if (/^umami--([a-z]+)--([a-z0-9_]+[a-z0-9-_]+)$/.test(className)) {
const [, type, value] = className.split('--'); const [, type, value] = className.split('--');
if (type && value) { const listener = () => pageEvent(type, value);
const listener = () => pageEvent(type, value);
listeners.push([element, type, listener]); listeners.push([element, type, listener]);
element.addEventListener(type, listener, true); element.addEventListener(type, listener, true);
}
} }
}); });
}); });

View File

@ -38,5 +38,12 @@ create table event (
); );
create index on session(created_at); create index on session(created_at);
create index on session(website_id);
create index on pageview(created_at); create index on pageview(created_at);
create index on pageview(website_id);
create index on pageview(session_id);
create index on event(created_at); create index on event(created_at);
create index on event(website_id);
create index on event(session_id);