From 5c5154ee86404961c9d6a9fd113e6fb2a8d7cf8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl-Gerhard=20Lindesva=CC=88rd?= Date: Wed, 4 Jun 2025 12:00:45 +0200 Subject: [PATCH] fix: clear cache for organizations when subscriptions updates --- apps/api/src/controllers/webhook.controller.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/apps/api/src/controllers/webhook.controller.ts b/apps/api/src/controllers/webhook.controller.ts index abff1df2..70db830b 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, });