OfficeDev / teams-toolkit

Developer tools for building Teams apps
Other
458 stars 188 forks source link

FindMember - API is very slow after adding 600+ conversations into storage #12562

Open inopassdev opened 5 days ago

inopassdev commented 5 days ago

Describe the bug

On the TeamsFX - TypeScript, the findMember method has become very slow since I have more than 600 persisted conversations in my storage. When I first put my Teams Bot into production, sending proactive notifications to a Teams user took about 7 seconds (With less conversations stored ~10), now it's 15 minutes.

To Reproduce Steps to reproduce the behavior:

  1. Send any adaptive card to my endpoint (See code below)
  2. The request is being processed
  3. findMember list every conversations on the storage, get them and try to get member informations from an MS API.
  4. The user receive the notification, 15-20min after the request started to be processed

More details The bot only send notifications to my users. To find the right user, I use the findMember method available on BotBuilderCloudAdapter.ConversationBot class. The condition used for matching is member.account.email === email. 1:1 conversations are stored in an Azure blob storage compatible bucket.

VS Code Extension Information (please complete the following information):

          const member = await notificationApp.notification.findMember(
            m => {
              return Promise.resolve(m.account.email === data.email)
            }, BotBuilderCloudAdapter.SearchScope.Person);

          await member?.sendAdaptiveCard(
            AdaptiveCards.declare(notificationTemplate).render({
              title: data.header,
              message:  data.message
            })
// Create bot.
export const notificationApp = new ConversationBot({
  // The bot id and password to create CloudAdapter.
  // See https://aka.ms/about-bot-adapter to learn more about adapters.
  adapterConfig: {
    MicrosoftAppId: config.botId,
    MicrosoftAppPassword: config.botPassword,
    MicrosoftAppType: "MultiTenant",
  },
  // Enable notification
  notification: {
    enabled: true,
    store: new BlobStore(connectionString, containerName),

  },
});
microsoft-github-policy-service[bot] commented 5 days ago

Thank you for contacting us! Any issue or feedback from you is quite important to us. We will do our best to fully respond to your issue as soon as possible. Sometimes additional investigations may be needed, we will usually get back to you within 2 days by adding comments to this issue. Please stay tuned.

swatDong commented 4 days ago

Since currently there's no cache inside TeamsFx SDK, it's expected the two sets of remote calls taking time.

  1. list all person targets from BlobStore
  2. get member details by calling TeamsInfo.getPagedMembers

For now one workaround is to add logic to your BlobStore.add, e.g.,