Weiko 3689e89440 Optimize upgrade status gauges with count-only queries (#23574)
## Context

Upgrade health metrics and the admin upgrade-status query currently
share `getInstanceAndAllWorkspacesStatus`.

On a cache hit, that method reads the cached behind/failed workspace
IDs, then hydrates every workspace name with an individual
`CoreEntityCacheService.get` call. This is useful for the admin
response, but the gauges only need the number of workspaces in each
state.

As the number of behind or failed workspaces grows, every gauge refresh
therefore creates a fan-out of entity-cache lookups. Those lookups can
include Redis validation and response deserialization. Production
profiling of slow upgrade-status requests showed
`loadWorkspaceNamesById` and `CoreEntityCacheService.get` on the hot
path, so this PR removes that unnecessary repeated work.

## What changed

- Added a count-only upgrade-status method for metric collection.
- Updated upgrade gauges to use cached ID counts without loading
workspace names.
- Replaced the admin path's per-workspace cache lookups with one
repository query selecting only `id` and `displayName`.
- Removed the upgrade module's now-unused core-entity-cache dependency.

## Why this improves performance

### Metrics path

Before:

- Read the cached upgrade-status IDs.
- Run one entity-cache lookup per behind/failed workspace.
- Discard the hydrated names and only use the array lengths.

After:

- Read the same cached upgrade-status IDs.
- Derive counts directly from those IDs.
- Perform no workspace-name lookup.

**This changes metric collection from a fixed set of status-cache calls
plus `N` entity-cache calls to only the fixed status-cache calls. The
amount of ID data still scales with the number of affected workspaces,
but the Redis/client round-trip fan-out does not.**

### Admin path

The admin response still needs workspace names. It now loads them with
one primary-key `IN` query instead of `N` independent entity-cache
calls. This reduces round trips and repeated cache validation while
preserving the response shape.

## Safety and behavior preservation

- Upgrade-status cache keys, TTLs and invalidation behavior are
unchanged.
- A missing cache marker still triggers the existing full status
refresh.
- Metrics names and values are unchanged.
- The admin GraphQL response is unchanged.
- Cached workspace IDs missing from the database still produce a `null`
name, matching the previous behavior.
- The batched query runs only for callers that request the detailed
admin payload, not for metric collection.

## Expected impact

- Remove recurring per-workspace cache fan-out from every API process
collecting upgrade gauges.
- Reduce Redis client work, response deserialization and event-loop
pressure during metric collection.
- Reduce latency for detailed admin upgrade-status requests.

This targets one profiled source of tail latency. It is not expected to
eliminate all API p99 outliers, which also have independent causes.

## Validation

- 36 focused upgrade-status and gauge tests pass.
- `yarn nx typecheck twenty-server` passes.
- Oxlint passes with zero warnings and errors.
- Oxfmt and `git diff --check` pass.
2026-07-30 14:38:48 +00:00
2026-06-11 11:02:28 +02:00

Twenty logo

The #1 Open-Source CRM

Website · Documentation · Roadmap · Discord · Figma

Twenty banner


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 app:publish --private

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.

Create your apps

Learn more about apps in doc

Stay on top with version control

Learn more about version control in doc

All the tools you need to build anything

Learn more about primitives in doc

Customize your layouts

Learn more about layouts in doc

AI agents and chats

Learn more about AI in doc

Plus all the tools of a good CRM

Learn more about CRM features in doc


Stack

Thanks

Greptile      Sentry      Crowdin

Thanks to these amazing services that we use and recommend for code review (Greptile), catching bugs (Sentry) and translating (Crowdin).

Join the Community

Star the repo · Discord · Feature requests · Releases · X · LinkedIn · Crowdin · Contribute

S
Description
The open alternative to Salesforce, designed for AI.
Readme AGPL-3.0 1.4 GiB
Languages
TypeScript 79.6%
MDX 17.3%
JavaScript 2.7%
Python 0.2%
SCSS 0.1%