https://sonarly.com/issue/33412?type=bug The `canFeatureBeUsed` billing check called during every workflow trigger execution runs an expensive query with two levels of JOINed relations, but only checks if a subscription exists. Under worker load, this query times out at the 10-second `query_timeout` threshold, failing workflow runs. Fix: ## What changed Modified `canFeatureBeUsed()` in `billing-usage.service.ts` to use a lightweight direct query instead of calling `getCurrentBillingSubscription()`. ### Before `canFeatureBeUsed` called `billingSubscriptionService.getCurrentBillingSubscription({ workspaceId })` which runs a `find()` query with two levels of eagerly-loaded relations: - `billingSubscriptionItems` (JOIN to `billingSubscriptionItem` table) - `billingSubscriptionItems.billingProduct` (JOIN to `billingProduct` table) All of this just to check `!!billingSubscription` — a boolean existence check that doesn't use any of the loaded relations. ### After `canFeatureBeUsed` now queries `billingSubscriptionRepository.findOne()` directly with: - The same `where` filter: `{ workspaceId, status: Not(SubscriptionStatus.Canceled) }` - `select: ['id']` — only fetches the primary key column - No relations loaded This eliminates the two JOINs and reduces the query from a multi-table join returning all columns to a simple single-table lookup returning one column. The partial unique index `IDX_BILLING_SUBSCRIPTION_WORKSPACE_ID_UNIQUE` on `(workspaceId) WHERE status IN ('trialing', 'active', 'past_due')` can be used efficiently. ### Why this is safe - `billingSubscriptionRepository` is already injected in `BillingUsageService` (line 51-52) and used by other methods in the same class - `Not` and `SubscriptionStatus` were already imported in this file - The filter logic is identical to `getCurrentBillingSubscription` - The return value semantics are unchanged: truthy if a non-canceled subscription exists, falsy otherwise - The two callers (`workflow-runner.workspace-service.ts` and `billing-usage-event.listener.ts`) both only check the boolean result
The #1 Open-Source CRM
Website ·
Documentation ·
Roadmap ·
Discord ·
Figma
Why Twenty
Twenty gives technical teams the building blocks for a custom CRM that meets complex business needs and quickly adapts as the business evolves. Twenty is the CRM you build, ship, and version like the rest of your stack.
Learn more about why we built Twenty
Installation
Cloud
The fastest way to get started. Sign up at twenty.com and spin up a workspace in under a minute, with no infrastructure to manage and always up to date.
Build an app
Scaffold a new app with the Twenty CLI:
npx create-twenty-app my-app
Define objects, fields, and views as code:
import { defineObject, FieldType } from 'twenty-sdk/define';
export default defineObject({
nameSingular: 'deal',
namePlural: 'deals',
labelSingular: 'Deal',
labelPlural: 'Deals',
fields: [
{ name: 'name', label: 'Name', type: FieldType.TEXT },
{ name: 'amount', label: 'Amount', type: FieldType.CURRENCY },
{ name: 'closeDate', label: 'Close Date', type: FieldType.DATE_TIME },
],
});
Then ship it to your workspace:
npx twenty deploy
See the app development guide for objects, views, agents, and logic functions.
Self-hosting
Run Twenty on your own infrastructure with Docker Compose, or contribute locally via the local setup guide.
Everything you need
Twenty gives you the building blocks of a modern CRM (objects, views, workflows, and agents) and lets you extend them as code. Here's a tour of what's in the box.
Want to go deeper? Read the User Guide for product walkthroughs, or the
Documentation for developer reference.
|
|
|
|
|
|
Stack
TypeScript
Nx
NestJS, with BullMQ,
PostgreSQL,
Redis
React, with Jotai, Linaria and Lingui
Thanks
Thanks to these amazing services that we use and recommend for UI testing (Chromatic), code review (Greptile), catching bugs (Sentry) and translating (Crowdin).
Join the Community
Star the repo ·
Discord ·
Feature requests ·
Releases ·
X ·
LinkedIn ·
Crowdin ·
Contribute





