Skip to content

OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.

fix: ensure we dont bloat notification table with any other notification than app

Carl-Gerhard Lindesvärd52b86682e23f
diff --git a/apps/dashboard/src/components/notifications/notification-provider.tsx b/apps/dashboard/src/components/notifications/notification-provider.tsx
index 0824ab352..fb50a6c2c 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<Notification>(`/live/notifications/${projectId}`, (notification) => {
- toast(notification.title, {
- description: notification.message,
- icon: <BellIcon className="size-4" />,
- });
- });
+ useWS<Prisma.NotificationUncheckedCreateInput>(
+ `/live/notifications/${projectId}`,
+ (notification) => {
+ toast(notification.title, {
+ description: notification.message,
+ icon: <BellIcon className="size-4" />,
+ });
+ },
+ );
return null;
}
diff --git a/apps/dashboard/src/components/notifications/table/columns.tsx b/apps/dashboard/src/components/notifications/table/columns.tsx
index d9d783750..94107cd6e 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 <div>{integration?.name}</div>;
- },
- },
{
accessorKey: 'notificationRule',
header: 'Rule',
diff --git a/packages/db/src/services/notification.service.ts b/packages/db/src/services/notification.service.ts
index 49b224e0d..375703ee3 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 672f02d88..54a6dce0a 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<MiscQueuePayload>('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 fed6c4b9a..2bcca054a 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;
};
};