From 1df5fd513aaf08da2e1f100c95f435d7d978ad8e Mon Sep 17 00:00:00 2001 From: Sivin Varghese <64252451+iamsivin@users.noreply.github.com> Date: Mon, 1 Dec 2025 13:36:34 +0530 Subject: [PATCH] fix: Reduce unnecessary label suggestion API calls (#12978) --- .../components/widgets/conversation/MessagesView.vue | 6 ++++-- .../dashboard/store/modules/conversations/index.js | 2 -- .../store/modules/specs/conversations/mutations.spec.js | 1 - app/javascript/shared/constants/busEvents.js | 1 - 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/app/javascript/dashboard/components/widgets/conversation/MessagesView.vue b/app/javascript/dashboard/components/widgets/conversation/MessagesView.vue index 3cb46c05f..8d35308cb 100644 --- a/app/javascript/dashboard/components/widgets/conversation/MessagesView.vue +++ b/app/javascript/dashboard/components/widgets/conversation/MessagesView.vue @@ -258,8 +258,6 @@ export default { created() { emitter.on(BUS_EVENTS.SCROLL_TO_MESSAGE, this.onScrollToMessage); - // when a new message comes in, we refetch the label suggestions - emitter.on(BUS_EVENTS.FETCH_LABEL_SUGGESTIONS, this.fetchSuggestions); // when a message is sent we set the flag to true this hides the label suggestions, // until the chat is changed and the flag is reset in the watch for currentChat emitter.on(BUS_EVENTS.MESSAGE_SENT, () => { @@ -291,6 +289,10 @@ export default { return; } + // Early exit if conversation already has labels - no need to suggest more + const existingLabels = this.currentChat?.labels || []; + if (existingLabels.length > 0) return; + // method available in mixin, need to ensure that integrations are present await this.fetchIntegrationsIfRequired(); diff --git a/app/javascript/dashboard/store/modules/conversations/index.js b/app/javascript/dashboard/store/modules/conversations/index.js index 2ee6fd061..c79e31de1 100644 --- a/app/javascript/dashboard/store/modules/conversations/index.js +++ b/app/javascript/dashboard/store/modules/conversations/index.js @@ -194,7 +194,6 @@ export const mutations = { const { conversation: { unread_count: unreadCount = 0 } = {} } = message; chat.unread_count = unreadCount; if (selectedChatId === conversationId) { - emitter.emit(BUS_EVENTS.FETCH_LABEL_SUGGESTIONS); emitter.emit(BUS_EVENTS.SCROLL_TO_MESSAGE); } } @@ -225,7 +224,6 @@ export const mutations = { const { messages, ...updates } = conversation; allConversations[index] = { ...selectedConversation, ...updates }; if (_state.selectedChatId === conversation.id) { - emitter.emit(BUS_EVENTS.FETCH_LABEL_SUGGESTIONS); emitter.emit(BUS_EVENTS.SCROLL_TO_MESSAGE); } } else { diff --git a/app/javascript/dashboard/store/modules/specs/conversations/mutations.spec.js b/app/javascript/dashboard/store/modules/specs/conversations/mutations.spec.js index b8660b20d..48e676215 100644 --- a/app/javascript/dashboard/store/modules/specs/conversations/mutations.spec.js +++ b/app/javascript/dashboard/store/modules/specs/conversations/mutations.spec.js @@ -753,7 +753,6 @@ describe('#mutations', () => { }; mutations[types.UPDATE_CONVERSATION](state, conversation); - expect(emitter.emit).toHaveBeenCalledWith('FETCH_LABEL_SUGGESTIONS'); expect(emitter.emit).toHaveBeenCalledWith('SCROLL_TO_MESSAGE'); }); diff --git a/app/javascript/shared/constants/busEvents.js b/app/javascript/shared/constants/busEvents.js index 0d5661d26..ef8f24155 100644 --- a/app/javascript/shared/constants/busEvents.js +++ b/app/javascript/shared/constants/busEvents.js @@ -4,7 +4,6 @@ export const BUS_EVENTS = { FOCUS_CUSTOM_ATTRIBUTE: 'FOCUS_CUSTOM_ATTRIBUTE', SCROLL_TO_MESSAGE: 'SCROLL_TO_MESSAGE', MESSAGE_SENT: 'MESSAGE_SENT', - FETCH_LABEL_SUGGESTIONS: 'FETCH_LABEL_SUGGESTIONS', ON_MESSAGE_LIST_SCROLL: 'ON_MESSAGE_LIST_SCROLL', WEBSOCKET_DISCONNECT: 'WEBSOCKET_DISCONNECT', WEBSOCKET_RECONNECT: 'WEBSOCKET_RECONNECT',