mirror of
https://github.com/Litlyx/litlyx
synced 2025-12-10 07:48:37 +01:00
add domain filter on events
This commit is contained in:
@@ -1,17 +1,16 @@
|
||||
|
||||
import { Redis } from "~/server/services/CacheService";
|
||||
import { getRequestDataOld } from "~/server/utils/getRequestData";
|
||||
|
||||
export default defineEventHandler(async event => {
|
||||
|
||||
|
||||
const data = await getRequestDataOld(event, { requireSchema: true });
|
||||
const data = await getRequestData(event, ['GUEST', 'DOMAIN', 'RANGE', 'SCHEMA']);
|
||||
if (!data) return;
|
||||
|
||||
const { schemaName, pid, from, to, model, project_id } = data;
|
||||
const { schemaName, pid, from, to, model, project_id, domain } = data;
|
||||
|
||||
const cacheKey = `count:${schemaName}:${pid}:${from}:${to}`;
|
||||
const cacheExp = 60;
|
||||
const cacheKey = `count:${schemaName}:${pid}:${from}:${to}:${domain}`;
|
||||
const cacheExp = 20;
|
||||
|
||||
return await Redis.useCacheV2(cacheKey, cacheExp, async () => {
|
||||
|
||||
@@ -19,7 +18,8 @@ export default defineEventHandler(async event => {
|
||||
{
|
||||
$match: {
|
||||
project_id,
|
||||
created_at: { $gte: new Date(from), $lte: new Date(to) }
|
||||
created_at: { $gte: new Date(from), $lte: new Date(to) },
|
||||
website: domain
|
||||
}
|
||||
},
|
||||
{ $count: 'count' },
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
|
||||
import { EventModel } from "@schema/metrics/EventSchema";
|
||||
import { Redis } from "~/server/services/CacheService";
|
||||
import { getRequestDataOld } from "~/server/utils/getRequestData";
|
||||
|
||||
export default defineEventHandler(async event => {
|
||||
|
||||
const data = await getRequestDataOld(event, { requireSchema: false });
|
||||
const data = await getRequestData(event, ['GUEST', 'DOMAIN', 'RANGE']);
|
||||
if (!data) return;
|
||||
|
||||
const { pid, from, to, project_id, limit } = data;
|
||||
const { pid, from, to, project_id, limit, domain } = data;
|
||||
|
||||
const cacheKey = `events:${pid}:${limit}:${from}:${to}`;
|
||||
const cacheExp = 60;
|
||||
const cacheKey = `events:${pid}:${limit}:${from}:${to}:${domain}`;
|
||||
const cacheExp = 20;
|
||||
|
||||
return await Redis.useCacheV2(cacheKey, cacheExp, async () => {
|
||||
|
||||
@@ -19,7 +18,8 @@ export default defineEventHandler(async event => {
|
||||
{
|
||||
$match: {
|
||||
project_id,
|
||||
created_at: { $gte: new Date(from), $lte: new Date(to) }
|
||||
created_at: { $gte: new Date(from), $lte: new Date(to) },
|
||||
website: domain
|
||||
}
|
||||
},
|
||||
{ $group: { _id: "$name", count: { $sum: 1, } } },
|
||||
|
||||
Reference in New Issue
Block a user