This commit is contained in:
Carl-Gerhard Lindesvärd
2024-02-13 11:25:14 +01:00
parent 034be63ac0
commit 7f2c0f6cf0
64 changed files with 5820 additions and 1160 deletions

View File

@@ -4,3 +4,4 @@ export * from './src/clickhouse-client';
export * from './src/sql-builder';
export * from './src/services/salt';
export * from './src/services/event.service';
export * from './src/services/share.service';

View File

@@ -0,0 +1,19 @@
-- CreateTable
CREATE TABLE "shares" (
"id" TEXT NOT NULL,
"project_id" TEXT NOT NULL,
"organization_slug" TEXT NOT NULL,
"public" BOOLEAN NOT NULL DEFAULT false,
"password" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP
);
-- CreateIndex
CREATE UNIQUE INDEX "shares_id_key" ON "shares"("id");
-- CreateIndex
CREATE UNIQUE INDEX "shares_project_id_key" ON "shares"("project_id");
-- AddForeignKey
ALTER TABLE "shares" ADD CONSTRAINT "shares_project_id_fkey" FOREIGN KEY ("project_id") REFERENCES "projects"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

View File

@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "shares" ALTER COLUMN "password" DROP NOT NULL;

View File

@@ -19,10 +19,11 @@ model Project {
profiles Profile[]
clients Client[]
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
reports Report[]
dashboards Dashboard[]
share ShareOverview?
@@map("projects")
}
@@ -151,3 +152,16 @@ model Waitlist {
@@map("waitlist")
}
model ShareOverview {
id String @unique
project_id String @unique
project Project @relation(fields: [project_id], references: [id])
organization_slug String
public Boolean @default(false)
password String?
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
@@map("shares")
}

View File

@@ -92,6 +92,11 @@ interface GetEventsOptions {
profile?: boolean | Prisma.ProfileSelect;
}
export async function getLiveVisitors(projectId: string) {
const keys = await redis.keys(`live:event:${projectId}:*`);
return keys.length;
}
export async function getEvents(sql: string, options: GetEventsOptions = {}) {
const events = await chQuery<IClickhouseEvent>(sql);
if (options.profile) {
@@ -186,7 +191,12 @@ export async function createEvent(payload: IServiceCreateEventPayload) {
});
redisPub.publish('event', JSON.stringify(transformEvent(event)));
redis.set(`live:event:${event.project_id}:${event.profile_id}`, '', 'EX', 10);
redis.set(
`live:event:${event.project_id}:${event.profile_id}`,
'',
'EX',
60 * 5
);
return {
...res,

View File

@@ -0,0 +1,12 @@
import { db } from '../prisma-client';
export function getShareOverviewById(id: string) {
return db.shareOverview.findFirst({
where: {
id,
},
include: {
project: true,
},
});
}