From 52b86682e23fd4363cf29ab23e9be045399de7e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl-Gerhard=20Lindesva=CC=88rd?= Date: Wed, 3 Sep 2025 21:39:21 +0200 Subject: [PATCH] fix: ensure we dont bloat notification table with any other notification than app --- .../notifications/notification-provider.tsx | 17 +++++----- .../notifications/table/columns.tsx | 8 ----- .../db/src/services/notification.service.ts | 31 ++++++++++++------- packages/queue/src/queues.ts | 4 +-- packages/redis/publisher.ts | 4 +-- 5 files changed, 33 insertions(+), 31 deletions(-) diff --git a/apps/dashboard/src/components/notifications/notification-provider.tsx b/apps/dashboard/src/components/notifications/notification-provider.tsx index 0824ab35..fb50a6c2 100644 --- a/apps/dashboard/src/components/notifications/notification-provider.tsx +++ b/apps/dashboard/src/components/notifications/notification-provider.tsx @@ -1,6 +1,6 @@ import { useAppParams } from '@/hooks/useAppParams'; import useWS from '@/hooks/useWS'; -import type { Notification } from '@openpanel/db'; +import type { Prisma } from '@openpanel/db'; import { BellIcon } from 'lucide-react'; import { toast } from 'sonner'; @@ -15,12 +15,15 @@ export function NotificationProvider() { export function InnerNotificationProvider({ projectId, }: { projectId: string }) { - useWS(`/live/notifications/${projectId}`, (notification) => { - toast(notification.title, { - description: notification.message, - icon: , - }); - }); + useWS( + `/live/notifications/${projectId}`, + (notification) => { + toast(notification.title, { + description: notification.message, + icon: , + }); + }, + ); return null; } diff --git a/apps/dashboard/src/components/notifications/table/columns.tsx b/apps/dashboard/src/components/notifications/table/columns.tsx index d9d78375..94107cd6 100644 --- a/apps/dashboard/src/components/notifications/table/columns.tsx +++ b/apps/dashboard/src/components/notifications/table/columns.tsx @@ -46,14 +46,6 @@ export function useColumns() { ); }, }, - { - accessorKey: 'integration', - header: 'Integration', - cell({ row }) { - const integration = row.original.integration; - return
{integration?.name}
; - }, - }, { accessorKey: 'notificationRule', header: 'Rule', diff --git a/packages/db/src/services/notification.service.ts b/packages/db/src/services/notification.service.ts index 49b224e0..375703ee 100644 --- a/packages/db/src/services/notification.service.ts +++ b/packages/db/src/services/notification.service.ts @@ -117,21 +117,28 @@ function getIntegration(integrationId: string | null) { } export async function createNotification(notification: ICreateNotification) { - const res = await db.notification.create({ - data: { - title: notification.title, - message: notification.message, - projectId: notification.projectId, - payload: notification.payload || Prisma.DbNull, - ...getIntegration(notification.integrationId), - notificationRuleId: notification.notificationRuleId, - }, - }); + const data: Prisma.NotificationUncheckedCreateInput = { + title: notification.title, + message: notification.message, + projectId: notification.projectId, + payload: notification.payload || Prisma.DbNull, + ...getIntegration(notification.integrationId), + notificationRuleId: notification.notificationRuleId, + }; - return triggerNotification(res); + // Only create notifications for app + if (data.sendToApp) { + await db.notification.create({ + data, + }); + } + + return triggerNotification(data); } -export function triggerNotification(notification: Notification) { +export function triggerNotification( + notification: Prisma.NotificationUncheckedCreateInput, +) { return notificationQueue.add('sendNotification', { type: 'sendNotification', payload: { diff --git a/packages/queue/src/queues.ts b/packages/queue/src/queues.ts index 672f02d8..54a6dce0 100644 --- a/packages/queue/src/queues.ts +++ b/packages/queue/src/queues.ts @@ -1,6 +1,6 @@ import { Queue, QueueEvents } from 'bullmq'; -import type { IServiceEvent, Notification } from '@openpanel/db'; +import type { IServiceEvent, Notification, Prisma } from '@openpanel/db'; import { getRedisQueue } from '@openpanel/redis'; import type { TrackPayload } from '@openpanel/sdk'; @@ -130,7 +130,7 @@ export const miscQueue = new Queue('misc', { export type NotificationQueuePayload = { type: 'sendNotification'; payload: { - notification: Notification; + notification: Prisma.NotificationUncheckedCreateInput; }; }; diff --git a/packages/redis/publisher.ts b/packages/redis/publisher.ts index fed6c4b9..2bcca054 100644 --- a/packages/redis/publisher.ts +++ b/packages/redis/publisher.ts @@ -1,6 +1,6 @@ import { type Redis, getRedisPub, getRedisSub } from './redis'; -import type { IServiceEvent, Notification } from '@openpanel/db'; +import type { IServiceEvent, Notification, Prisma } from '@openpanel/db'; import { getSuperJson, setSuperJson } from '@openpanel/json'; export type IPublishChannels = { @@ -14,7 +14,7 @@ export type IPublishChannels = { saved: IServiceEvent; }; notification: { - created: Notification; + created: Prisma.NotificationUncheckedCreateInput; }; };