Skip to content

Invalidate flat cache command#17442

Merged
prastoin merged 3 commits intomainfrom
invalidate-cache-command
Jan 26, 2026
Merged

Invalidate flat cache command#17442
prastoin merged 3 commits intomainfrom
invalidate-cache-command

Conversation

@prastoin
Copy link
Copy Markdown
Contributor

@prastoin prastoin commented Jan 26, 2026

Introduction

A command allowing to invalidate flat cache entries. Extends the active or suspended workspace coverage.

Args

--metadataName

If provided will invalidate metadata and related metadata cache entry ( can be repeated see usage )

--all-metadata

Will invalidate all metadata entries

Usage example

npx nx command twenty-server cache:flat-cache-invalidate --metadataName viewFilter --metadataName objectMetadata
npx nx command twenty-server cache:flat-cache-invalidate --all-metadata -w 0000-0000-0000-0000

@prastoin prastoin marked this pull request as ready for review January 26, 2026 12:50
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Jan 26, 2026

Greptile Overview

Greptile Summary

Added a new CLI command cache:flat-cache-invalidate that allows administrators to invalidate flat cache entries for specific metadata types or all metadata across active or suspended workspaces.

Key Changes:

  • Created FlatCacheInvalidateCommand that extends ActiveOrSuspendedWorkspacesMigrationCommandRunner to iterate over workspaces
  • Supports --metadataName flag (repeatable) to target specific metadata types or --all to invalidate all metadata
  • Validates metadata names against ALL_METADATA_NAME and automatically includes related metadata for comprehensive cache invalidation
  • Registered the command in WorkspaceManyOrAllFlatEntityMapsCacheModule with proper dependency injection

Recommendations:

  • Consider adding tests for this command following the AAA pattern outlined in testing guidelines (custom instruction 458c2737-e49d-49c4-a233-2605d1516703)
  • The PR description mentions --all with -w workspace ID in the usage example, verify this combination works as expected since the base runner handles workspace filtering

Confidence Score: 4/5

  • This PR is safe to merge with minimal risk - it adds a new administrative command without modifying existing functionality
  • The implementation follows established patterns in the codebase (extends existing command runner, proper validation), has clear error handling, and is isolated to a new command. One point deducted for missing tests which are recommended for new functionality per the testing guidelines.
  • No files require special attention - the implementation is straightforward and follows existing patterns

Important Files Changed

Filename Overview
packages/twenty-server/src/engine/core-modules/cache-storage/commands/flat-cache-invalidate.command.ts New command to invalidate flat cache entries for metadata. Implements validation, related metadata expansion, and workspace iteration. Minor concerns with testing coverage and error handling.
packages/twenty-server/src/engine/metadata-modules/flat-entity/services/workspace-many-or-all-flat-entity-maps-cache.module.ts Module registration for the new command. Correctly imports dependencies and exports the command.

Sequence Diagram

sequenceDiagram
    participant User
    participant FlatCacheInvalidateCommand
    participant ActiveOrSuspendedWorkspacesMigrationCommandRunner
    participant ValidationLogic
    participant UtilityFunctions
    participant WorkspaceManyOrAllFlatEntityMapsCacheService
    participant WorkspaceCacheService

    User->>FlatCacheInvalidateCommand: Execute command with --metadataName or --all
    FlatCacheInvalidateCommand->>FlatCacheInvalidateCommand: parseMetadataName() / parseAll()
    FlatCacheInvalidateCommand->>FlatCacheInvalidateCommand: runMigrationCommand()
    
    alt Missing both --all and --metadataName
        FlatCacheInvalidateCommand->>User: Error: Either --all or --metadataName required
    end
    
    FlatCacheInvalidateCommand->>ValidationLogic: validateAndExpandMetadataNames()
    ValidationLogic->>ValidationLogic: Check against ALL_METADATA_NAME
    
    alt Invalid metadata names
        ValidationLogic->>User: Error: Invalid metadata names
    else Valid
        ValidationLogic-->>FlatCacheInvalidateCommand: Return AllMetadataName[]
    end
    
    FlatCacheInvalidateCommand->>UtilityFunctions: computeFlatMapsKeysWithRelated()
    UtilityFunctions->>UtilityFunctions: getMetadataRelatedMetadataNames()
    UtilityFunctions->>UtilityFunctions: getMetadataFlatEntityMapsKey()
    UtilityFunctions-->>FlatCacheInvalidateCommand: Return flat maps keys
    
    FlatCacheInvalidateCommand->>ActiveOrSuspendedWorkspacesMigrationCommandRunner: super.runMigrationCommand()
    
    loop For each workspace
        ActiveOrSuspendedWorkspacesMigrationCommandRunner->>FlatCacheInvalidateCommand: runOnWorkspace()
        FlatCacheInvalidateCommand->>WorkspaceManyOrAllFlatEntityMapsCacheService: invalidateFlatEntityMaps()
        WorkspaceManyOrAllFlatEntityMapsCacheService->>WorkspaceCacheService: invalidateAndRecompute()
        WorkspaceCacheService-->>WorkspaceManyOrAllFlatEntityMapsCacheService: Cache invalidated
        WorkspaceManyOrAllFlatEntityMapsCacheService-->>FlatCacheInvalidateCommand: Complete
        FlatCacheInvalidateCommand->>User: Log: Successfully flushed cache for workspace
    end
    
    ActiveOrSuspendedWorkspacesMigrationCommandRunner-->>User: Command complete
Loading

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jan 26, 2026

🚀 Preview Environment Ready!

Your preview environment is available at: http://bore.pub:5259

This environment will automatically shut down when the PR is closed or after 5 hours.

@prastoin prastoin enabled auto-merge January 26, 2026 13:03
@prastoin prastoin added this pull request to the merge queue Jan 26, 2026
Merged via the queue into main with commit 406e269 Jan 26, 2026
61 of 62 checks passed
@prastoin prastoin deleted the invalidate-cache-command branch January 26, 2026 13:20
@twenty-eng-sync
Copy link
Copy Markdown

Hey @prastoin! After you've done the QA of your Pull Request, you can mark it as done here. Thank you!

1 similar comment
@twenty-eng-sync
Copy link
Copy Markdown

Hey @prastoin! After you've done the QA of your Pull Request, you can mark it as done here. Thank you!

etiennejouan pushed a commit that referenced this pull request Jan 27, 2026
# Introduction
A command allowing to invalidate flat cache entries. Extends the active
or suspended workspace coverage.

## Args
### --metadataName
If provided will invalidate metadata and related metadata cache entry (
can be repeated see usage )

### --all-metadata
Will invalidate all metadata entries

## Usage example
```
npx nx command twenty-server cache:flat-cache-invalidate --metadataName viewFilter --metadataName objectMetadata
```

```
npx nx command twenty-server cache:flat-cache-invalidate --all-metadata -w 0000-0000-0000-0000
```
camilo-agudelo-uma pushed a commit to innovation-grupo-uma/twenty-uma that referenced this pull request Feb 2, 2026
# Introduction
A command allowing to invalidate flat cache entries. Extends the active
or suspended workspace coverage.

## Args
### --metadataName
If provided will invalidate metadata and related metadata cache entry (
can be repeated see usage )

### --all-metadata
Will invalidate all metadata entries

## Usage example
```
npx nx command twenty-server cache:flat-cache-invalidate --metadataName viewFilter --metadataName objectMetadata
```

```
npx nx command twenty-server cache:flat-cache-invalidate --all-metadata -w 0000-0000-0000-0000
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants