Skip to content

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

fix: clear cache for organizations when subscriptions updates

Carl-Gerhard Lindesvärd5c5154ee8640
diff --git a/apps/api/src/controllers/webhook.controller.ts b/apps/api/src/controllers/webhook.controller.ts
index abff1df21..70db830b3 100644
--- a/apps/api/src/controllers/webhook.controller.ts
+++ b/apps/api/src/controllers/webhook.controller.ts
@@ -1,6 +1,6 @@
import fs from 'node:fs';
import path from 'node:path';
-import { db } from '@openpanel/db';
+import { db, getOrganizationByProjectIdCached } from '@openpanel/db';
import {
sendSlackNotification,
slackInstaller,
@@ -201,6 +201,16 @@ export async function polarWebhook(
},
});
+ const projects = await db.project.findMany({
+ where: {
+ organizationId: metadata.organizationId,
+ },
+ });
+
+ for (const project of projects) {
+ await getOrganizationByProjectIdCached.clear(project.id);
+ }
+
await publishEvent('organization', 'subscription_updated', {
organizationId: metadata.organizationId,
});