Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

⚡️ perf(channel): skip the routing settings read for mentioned messages (#21898)

AmAzing-2c88af522c79
diff --git a/apps/server/src/services/channel/ChannelService.routing.test.ts b/apps/server/src/services/channel/ChannelService.routing.test.ts
index c884ee9badb..346b708bd30 100644
--- a/apps/server/src/services/channel/ChannelService.routing.test.ts
+++ b/apps/server/src/services/channel/ChannelService.routing.test.ts
@@ -49,6 +49,9 @@ describe('Channel routing ingress', () => {
'channel',
expect.objectContaining({ mentions: ['coder'] }),
);
+ // A mentioned message is directed, so its routing settings are never needed.
+ expect(mocks.config).not.toHaveBeenCalled();
+ expect(mocks.wake).toHaveBeenCalledWith('channel');
});
it('schedules a retried attempt only after the permission-checked repository write', async () => {
mocks.retry.mockResolvedValue({ routingAttempt: 2 });
diff --git a/apps/server/src/services/channel/ChannelService.ts b/apps/server/src/services/channel/ChannelService.ts
index b6eeeecd8da..ee705c1c4fa 100644
--- a/apps/server/src/services/channel/ChannelService.ts
+++ b/apps/server/src/services/channel/ChannelService.ts
@@ -210,7 +210,10 @@ export class ChannelService {
};
send = async (channelId: string, input: Omit<ChannelSendInput, 'routing'>) => {
- const config = await resolveChannelRoutingConfig(this.db, this.userId);
+ // The repository directs any mentioned message itself and never reads its routing mode.
+ const config = input.mentions?.length
+ ? null
+ : await resolveChannelRoutingConfig(this.db, this.userId);
const message = await this.repository.send(channelId, {
...input,
routing: config ? 'decision' : 'fallback',