improve(api): update api to fastify v5

This commit is contained in:
Carl-Gerhard Lindesvärd
2025-02-28 09:19:27 +01:00
parent f0b0f27a8f
commit 7750ca117f
25 changed files with 520 additions and 1642 deletions

View File

@@ -4,7 +4,7 @@ import type { FastifyReply, FastifyRequest } from 'fastify';
import { generateDeviceId } from '@openpanel/common/server';
import { getSalts } from '@openpanel/db';
import { eventsQueue } from '@openpanel/queue';
import { getRedisCache } from '@openpanel/redis';
import { getLock } from '@openpanel/redis';
import type { PostEventPayload } from '@openpanel/sdk';
import { getStringHeaders, getTimestamp } from './track.controller';
@@ -42,12 +42,10 @@ export async function postEvent(
const isScreenView = request.body.name === 'screen_view';
// this will ensure that we don't have multiple events creating sessions
const LOCK_DURATION = 1000;
const locked = await getRedisCache().set(
const locked = await getLock(
`request:priority:${currentDeviceId}-${previousDeviceId}:${isScreenView ? 'screen_view' : 'other'}`,
'locked',
'PX',
LOCK_DURATION,
'NX',
);
await eventsQueue.add(
@@ -65,7 +63,7 @@ export async function postEvent(
geo,
currentDeviceId,
previousDeviceId,
priority: locked === 'OK',
priority: locked,
},
},
{