microsoftgraph / microsoftgraph/msgraph-sdk-powershell

Get-MgTeamChannelMessage Very Slow With Large Numbers of Messages

Open
#2,583 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Status: Needs Investigation
Dominant language
C#
Stars
898
Forks
230
Avg merge
2d 5h
Merged PRs (30d)
31

Description

Thanks for reporting the bug. Please ensure you've gone through the following checklist before opening an issue:

Describe the bug
Running the Get-MgTeamChannelMessage cmdlet against a channel with more than a hundred messages is very slow.

To Reproduce
Steps to reproduce the behavior:

  1. Select a channel with more than a couple of hundred messages.
  2. Run [array]$ChannelMessages = Get-MgTeamChannelMessage -TeamId $Team.Id -ChannelId $SelectedChannel.Id -All
  3. Wait...

Expected behavior
I expect the cmdlet to return all available messages in a reasonable period (a minute, maybe).

Debug Output

Run the problematic command with -Debug and paste the resulting debug stream below.
⚠ ATTENTION: Be sure to remove any sensitive information that may be in the logs.

Debug generates a stream of information as each message is retrieved. The retrieval of the messages gradually slows

{
  "id": "1584421259635",
  "replyToId": null,
  "etag": "1584421259635",
  "messageType": "message",
  "createdDateTime": "2020-03-17T05:00:59.635Z",
  "lastModifiedDateTime": "2020-03-17T05:00:59.635Z",
  "lastEditedDateTime": null,
  "deletedDateTime": null,
  "subject": null,
  "summary": "New tweet from @mpaez_tech about #Office365",
  "chatId": null,
  "importance": "normal",
  "locale": "en-us",
  "webUrl": "https://teams.microsoft.com/l/message/19%3A11e06f3f6cb842eba5847f4a4d637e5f%40thread.skype/1584421259635?groupId=e8cdd572-4a05-4065-90fa-832f5eb6c54e&tenantId=b662313f-14fc-43a2-9a7a-d2e27f4f3478&createdTime=1584421259635&parentMessageId=1584421259635",
  "policyViolation": null,
  "eventDetail": null,
  "from": {
    "device": null,
    "user": null,
    "application": {
      "@odata.type": "#microsoft.graph.teamworkApplicationIdentity",
      "id": "75a6c3a3-aadd-4f97-8118-99e7c2335cb2",
      "displayName": "Twitter",
      "applicationIdentityType": "office365Connector"
    }
  },
  "body": {
    "contentType": "html",
    "content": "<attachment id=\"ee5b1826ecb746a7a0f642e212b74c26\"></attachment>"
  },
  "channelIdentity": {
    "teamId": "e8cdd572-4a05-4065-90fa-832f5eb6c54e",
    "channelId": "19:11e06f3f6cb842eba5847f4a4d637e5f@thread.skype"
  },
  "attachments": [
    {
      "id": "ee5b1826ecb746a7a0f642e212b74c26",
      "contentType": "application/vnd.microsoft.teams.card.o365connector",
      "contentUrl": null,
      "content": "{\r\n  \"summary\": \"New tweet from @mpaez_tech about #Office365\",\r\n  \"text\": \"\",\r\n  \"sections\": [\r\n    {\r\n      \"text\": \"\",\r\n      \"title\": \"\",\r\n      \"activityTitle\": \"<p><a href=\\\"https://twitter.com/mpaez_tech/status/1239725545643966466\\\" title=\\\"MPaez_TECH\\\">MPaez_TECH</a></p>\",\r\n      \"activitySubtitle\": \"<p>@Netwrix</p>\",\r\n      \"activityText\": \"<p>Ready to take administration of Office 365 to a new level? Then grab this free <a href=\\\"https://twitter.com/hashtag/Office365?src=hash\\\" title=\\\"#Office365\\\">#Office365</a> guide packed with how-to’… <a href=\\\"https://twitter.com/i/web/status/1217088114705031169\\\" title=\\\"twitter.com/i/web/status/1…\\\">twitter.com/i/web/status/1…</a></p>\",\r\n      \"activityImage\": \"http://pbs.twimg.com/profile_images/973209482254848000/f6dLmD6o_normal.jpg\",\r\n      \"potentialAction\": [\r\n        {\r\n          \"hideCardOnInvoke\": false,\r\n          \"target\": \"https://api.twitter.com/\",\r\n          \"body\": \"{'commandName': 'Like', 'tweetId':'1217088114705031169'}\",\r\n          \"@type\": \"HttpPOST\",\r\n          \"@id\": \"47438c0b-a07f-4cd8-9969-b1948302e0e4\",\r\n          \"name\": \"Like\",\r\n          \"isPrimaryAction\": false\r\n        },\r\n        {\r\n          \"hideCardOnInvoke\": false,\r\n          \"target\": \"https://api.twitter.com/\",\r\n          \"body\": \"{'commandName': 'Retweet', 'tweetId':'1217088114705031169'}\",\r\n          \"@type\": \"HttpPOST\",\r\n          \"@id\": \"75646dfa-0504-47dc-a250-4b72404fa1ed\",\r\n          \"name\": \"Retweet\",\r\n          \"isPrimaryAction\": false\r\n        },\r\n        {\r\n          \"target\": [\r\n            \"https://twitter.com/Netwrix/status/1217088114705031169\"\r\n          ],\r\n          \"@context\": \"http://schema.org\",\r\n          \"@type\": \"ViewAction\",\r\n          \"name\": \"View in Twitter\",\r\n          \"isPrimaryAction\": false\r\n        }\r\n      ],\r\n      \"markdown\": true,\r\n      \"startGroup\": false\r\n    }\r\n  ]\r\n}",
      "name": null,
      "thumbnailUrl": null,
      "teamsAppId": null
    }
  ],
  "mentions": [],
  "reactions": []
},

Module Version
13.1

Environment Data
Name Value


PSVersion 7.4.1
PSEdition Core
GitCommitId 7.4.1
OS Microsoft Windows 10.0.22631
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0

Screenshots

If applicable, add screenshots to help explain your problem.

Additional context

Add any other context about the problem here.

I think the problem is with the Graph API. If I use the Graph equivalent to fetch messages, I see many instances of "too many retries performed" errors. Here's the code I used to test:

$Uri = ("https://graph.microsoft.com/v1.0/teams/{0}/channels/{1}/messages?top=50" -f $Team.Id, $SelectedChannel.Id)
[array]$Data = Invoke-MgGraphRequest -Uri $Uri -Method GET
[array]$ChannelMessages = $Data.Value

[int]$Page = 1
$NextLink = $Data.'@Odata.NextLink'
While ($NextLink -ne $null) {
[int]$Page++
Write-Host ("Fetching page {0} of team channel messages..." -f $Page)
$Uri = $NextLink
[array]$Data = Invoke-MgGraphRequest -Uri $Uri -Method GET
[array]$ChannelMessages += $Data.Value
$NextLink = $Data.'@Odata.NextLink'
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the slowdown with Get-MgTeamChannelMessage using -All against a channel with hundreds of messages, then compare it with the Invoke-MgGraphRequest pagination example and its debug output. Determine whether the delay is in the cmdlet or the Microsoft Graph endpoint; done means identifying a repository-side cause and a reproducible fix, or documenting that the service must be addressed.

Written by the indexing model from the issue text.

Assessment

Tech stack
powershell
Domain
api, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.