Skip to content

Commit

Permalink
Avoid slack-messages-count sequential queries to SQL when generating …
Browse files Browse the repository at this point in the history
…contentFragment (#2676)
  • Loading branch information
spolu authored Nov 27, 2023
1 parent f0e1175 commit 5987509
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
20 changes: 11 additions & 9 deletions connectors/src/connectors/slack/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,15 @@ async function makeContentFragment(
let next_cursor = undefined;

let shouldTake = false;

const slackBotMessages = await SlackChatBotMessage.findAll({
where: {
connectorId: connector.id,
channelId: channelId,
threadTs: threadTs,
},
});

do {
const replies: ConversationsRepliesResponse =
await slackClient.conversations.replies({
Expand Down Expand Up @@ -657,15 +666,8 @@ async function makeContentFragment(
continue;
}
if (shouldTake) {
const slackChatBotMessage = await SlackChatBotMessage.findOne({
where: {
connectorId: connector.id,
messageTs: m.ts,
channelId: channelId,
},
});
if (slackChatBotMessage) {
// If this message is a mention to the bot, we don't send it as a content fragment
if (slackBotMessages.find((sbm) => sbm.messageTs === m.ts)) {
// If this message is a mention to the bot, we don't send it as a content fragment.
continue;
}
allMessages.push(m);
Expand Down
1 change: 1 addition & 0 deletions connectors/src/lib/models/slack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ SlackChatBotMessage.init(
{
sequelize: sequelize_conn,
modelName: "slack_chat_bot_messages",
indexes: [{ fields: ["connectorId", "channelId", "threadTs"] }],
}
);
Connector.hasOne(SlackChatBotMessage);

0 comments on commit 5987509

Please sign in to comment.