Add message channel reset command#16266
Conversation
Greptile OverviewGreptile SummaryAdds a new CLI command
Minor optimization opportunity: the Confidence Score: 4/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
participant CLI as CLI Command
participant CMD as MessagingResetChannelCommand
participant ORM as TwentyORMGlobalManager
participant MCS as MessagingMessageCleanerService
participant Cache as CacheStorageService
participant DB as Database Repositories
CLI->>CMD: run(options)
CMD->>ORM: getRepositoryForWorkspace(messageChannel)
ORM-->>CMD: messageChannelRepository
alt Single Channel
CMD->>DB: findOne(messageChannelId)
DB-->>CMD: messageChannel
CMD->>CMD: resetMessageChannel()
else All Channels
CMD->>DB: find() all channels
DB-->>CMD: messageChannels[]
loop For each channel
CMD->>CMD: resetMessageChannel()
end
end
Note over CMD,DB: resetMessageChannel operations
CMD->>ORM: getRepositoryForWorkspace(messageChannelMessageAssociation)
ORM-->>CMD: associationRepository
CMD->>DB: find associations
DB-->>CMD: associations[]
alt Has message associations
CMD->>MCS: deleteMessagesChannelMessageAssociationsAndRelatedOrphans()
MCS->>DB: delete associations, orphan messages, orphan threads
end
CMD->>Cache: del(messages-to-import cache key)
CMD->>ORM: getRepositoryForWorkspace(messageFolder)
ORM-->>CMD: messageFolderRepository
CMD->>DB: update(syncCursor = null)
CMD->>DB: update channel(syncCursor, syncStage, syncStatus, etc.)
CMD-->>CLI: Success
|
| const messageChannelRepository = | ||
| await this.twentyORMGlobalManager.getRepositoryForWorkspace<MessageChannelWorkspaceEntity>( | ||
| workspaceId, | ||
| 'messageChannel', | ||
| ); |
There was a problem hiding this comment.
style: messageChannelRepository is already retrieved in the run method and could be passed as a parameter to avoid redundant database calls
| const messageChannelRepository = | |
| await this.twentyORMGlobalManager.getRepositoryForWorkspace<MessageChannelWorkspaceEntity>( | |
| workspaceId, | |
| 'messageChannel', | |
| ); | |
| private async resetMessageChannel( | |
| workspaceId: string, | |
| messageChannel: MessageChannelWorkspaceEntity, | |
| messageChannelRepository: Repository<MessageChannelWorkspaceEntity>, | |
| ): Promise<void> { |
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/twenty-server/src/modules/messaging/message-cleaner/commands/messaging-reset-channel.command.ts
Line: 105:109
Comment:
**style:** `messageChannelRepository` is already retrieved in the `run` method and could be passed as a parameter to avoid redundant database calls
```suggestion
private async resetMessageChannel(
workspaceId: string,
messageChannel: MessageChannelWorkspaceEntity,
messageChannelRepository: Repository<MessageChannelWorkspaceEntity>,
): Promise<void> {
```
How can I resolve this? If you propose a fix, please make it concise.|
🚀 Preview Environment Ready! Your preview environment is available at: http://bore.pub:48106 This environment will automatically shut down when the PR is closed or after 5 hours. |
...nty-server/src/modules/messaging/message-cleaner/commands/messaging-reset-channel.command.ts
Outdated
Show resolved
Hide resolved
...nty-server/src/modules/messaging/message-cleaner/commands/messaging-reset-channel.command.ts
Outdated
Show resolved
Hide resolved
charlesBochet
left a comment
There was a problem hiding this comment.
Left comment but approving
...nty-server/src/modules/messaging/message-cleaner/commands/messaging-reset-channel.command.ts
Fixed
Show fixed
Hide fixed
|
Hey @charlesBochet! After you've done the QA of your Pull Request, you can mark it as done here. Thank you! |
In this PR, we are adding a new command to reset a message channel.
We are also refactoring a bit cursor reset as we had multiple implementations at different places in the code base