Files
stats/packages/db/src/services/clients.service.ts
Carl-Gerhard Lindesvärd 4483e464d1 fix: optimize event buffer (#278)
* fix: how we fetch profiles in the buffer

* perf: optimize event buffer

* remove unused file

* fix

* wip

* wip: try groupmq 2

* try simplified event buffer with duration calculation on the fly instead
2026-03-16 13:29:40 +01:00

38 lines
802 B
TypeScript

import { cacheable } from '@openpanel/redis';
import type { Client, Prisma } from '../prisma-client';
import { db } from '../prisma-client';
export type IServiceClient = Client;
export type IServiceClientWithProject = Prisma.ClientGetPayload<{
include: {
project: true;
};
}>;
export async function getClientsByOrganizationId(organizationId: string) {
return db.client.findMany({
where: {
organizationId,
},
include: {
project: true,
},
orderBy: {
createdAt: 'asc',
},
});
}
export async function getClientById(
id: string,
): Promise<IServiceClientWithProject | null> {
return db.client.findUnique({
where: { id },
include: {
project: true,
},
});
}
export const getClientByIdCached = cacheable(getClientById, 60 * 5);