fix: read-after-write issues (#215)

* fix: read-after-write issues

* fix: coderabbit comments

* fix: clear cache on invite

* fix: use primary after a read
This commit is contained in:
Carl-Gerhard Lindesvärd
2025-10-31 09:56:07 +01:00
committed by GitHub
parent abacf66155
commit f454449365
19 changed files with 470 additions and 167 deletions

View File

@@ -113,6 +113,17 @@ export async function slackWebhook(
}
}
async function clearOrganizationCache(organizationId: string) {
const projects = await db.project.findMany({
where: {
organizationId,
},
});
for (const project of projects) {
await getOrganizationByProjectIdCached.clear(project.id);
}
}
export async function polarWebhook(
request: FastifyRequest<{
Querystring: unknown;
@@ -141,8 +152,11 @@ export async function polarWebhook(
},
data: {
subscriptionPeriodEventsCount: 0,
subscriptionPeriodEventsCountExceededAt: null,
},
});
await clearOrganizationCache(metadata.organizationId);
}
break;
}
@@ -205,15 +219,7 @@ 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 clearOrganizationCache(metadata.organizationId);
await publishEvent('organization', 'subscription_updated', {
organizationId: metadata.organizationId,