chore(root): migrate to biome
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import { chQuery, TABLE_NAMES } from '@openpanel/db';
|
||||
import { TABLE_NAMES, chQuery } from '@openpanel/db';
|
||||
|
||||
export async function ping() {
|
||||
const [res] = await chQuery<{ count: number }>(
|
||||
`SELECT COUNT(*) as count FROM ${TABLE_NAMES.events}`
|
||||
`SELECT COUNT(*) as count FROM ${TABLE_NAMES.events}`,
|
||||
);
|
||||
|
||||
if (typeof res?.count === 'number') {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { generateSalt } from '@openpanel/common';
|
||||
import { generateSalt } from '@openpanel/common/server';
|
||||
import { db, getCurrentSalt } from '@openpanel/db';
|
||||
|
||||
export async function salt() {
|
||||
|
||||
@@ -3,19 +3,19 @@ import { last } from 'ramda';
|
||||
|
||||
import { getTime } from '@openpanel/common';
|
||||
import {
|
||||
TABLE_NAMES,
|
||||
createEvent,
|
||||
eventBuffer,
|
||||
getEvents,
|
||||
TABLE_NAMES,
|
||||
} from '@openpanel/db';
|
||||
import type { EventsQueuePayloadCreateSessionEnd } from '@openpanel/queue';
|
||||
|
||||
export async function createSessionEnd(
|
||||
job: Job<EventsQueuePayloadCreateSessionEnd>
|
||||
job: Job<EventsQueuePayloadCreateSessionEnd>,
|
||||
) {
|
||||
const payload = job.data.payload;
|
||||
const eventsInBuffer = await eventBuffer.findMany(
|
||||
(item) => item.event.session_id === payload.sessionId
|
||||
(item) => item.event.session_id === payload.sessionId,
|
||||
);
|
||||
|
||||
const sql = `
|
||||
@@ -39,7 +39,7 @@ export async function createSessionEnd(
|
||||
const eventsInDb = await getEvents(sql);
|
||||
// sort last inserted first
|
||||
const events = [...eventsInBuffer, ...eventsInDb].sort(
|
||||
(a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime()
|
||||
(a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime(),
|
||||
);
|
||||
|
||||
events.map((event, index) => {
|
||||
@@ -51,7 +51,7 @@ export async function createSessionEnd(
|
||||
`DeviceId: ${event.deviceId}`,
|
||||
`Profile: ${event.profileId}`,
|
||||
`Path: ${event.path}`,
|
||||
].join('\n')
|
||||
].join('\n'),
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -128,7 +128,7 @@ export async function incomingEvent(job: Job<EventsQueuePayloadIncomingEvent>) {
|
||||
{
|
||||
delay: SESSION_END_TIMEOUT,
|
||||
jobId: sessionEndJobId,
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -178,7 +178,7 @@ export async function incomingEvent(job: Job<EventsQueuePayloadIncomingEvent>) {
|
||||
|
||||
function getSessionEndWithPriority(
|
||||
priority: boolean,
|
||||
count = 0
|
||||
count = 0,
|
||||
): typeof getSessionEnd {
|
||||
return async (args) => {
|
||||
const res = await getSessionEnd(args);
|
||||
@@ -208,13 +208,13 @@ async function getSessionEnd({
|
||||
previousDeviceId: string;
|
||||
}) {
|
||||
const sessionEndKeys = await getRedisQueue().keys(
|
||||
`*:sessionEnd:${projectId}:*`
|
||||
`*:sessionEnd:${projectId}:*`,
|
||||
);
|
||||
|
||||
const sessionEndJobCurrentDeviceId = await findJobByPrefix(
|
||||
sessionsQueue,
|
||||
sessionEndKeys,
|
||||
`sessionEnd:${projectId}:${currentDeviceId}:`
|
||||
`sessionEnd:${projectId}:${currentDeviceId}:`,
|
||||
);
|
||||
if (sessionEndJobCurrentDeviceId) {
|
||||
return { deviceId: currentDeviceId, job: sessionEndJobCurrentDeviceId };
|
||||
@@ -223,7 +223,7 @@ async function getSessionEnd({
|
||||
const sessionEndJobPreviousDeviceId = await findJobByPrefix(
|
||||
sessionsQueue,
|
||||
sessionEndKeys,
|
||||
`sessionEnd:${projectId}:${previousDeviceId}:`
|
||||
`sessionEnd:${projectId}:${previousDeviceId}:`,
|
||||
);
|
||||
if (sessionEndJobPreviousDeviceId) {
|
||||
return { deviceId: previousDeviceId, job: sessionEndJobPreviousDeviceId };
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { Job } from 'bullmq';
|
||||
import { escape } from 'sqlstring';
|
||||
|
||||
import { chQuery, db, TABLE_NAMES } from '@openpanel/db';
|
||||
import { TABLE_NAMES, chQuery, db } from '@openpanel/db';
|
||||
import type {
|
||||
EventsQueuePayload,
|
||||
EventsQueuePayloadCreateSessionEnd,
|
||||
@@ -24,7 +24,7 @@ export async function eventsJob(job: Job<EventsQueuePayload>) {
|
||||
}
|
||||
|
||||
return await createSessionEnd(
|
||||
job as Job<EventsQueuePayloadCreateSessionEnd>
|
||||
job as Job<EventsQueuePayloadCreateSessionEnd>,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,7 @@ export async function eventsJob(job: Job<EventsQueuePayload>) {
|
||||
|
||||
async function updateEventsCount(projectId: string) {
|
||||
const res = await chQuery<{ count: number }>(
|
||||
`SELECT count(*) as count FROM ${TABLE_NAMES.events} WHERE project_id = ${escape(projectId)}`
|
||||
`SELECT count(*) as count FROM ${TABLE_NAMES.events} WHERE project_id = ${escape(projectId)}`,
|
||||
);
|
||||
const count = res[0]?.count;
|
||||
if (count) {
|
||||
|
||||
Reference in New Issue
Block a user