msgraph-sdk-powershell
msgraph-sdk-powershell copied to clipboard
Get-MgTeamChannelMessage Very Slow With Large Numbers of Messages
Thanks for reporting the bug. Please ensure you've gone through the following checklist before opening an issue:
- Make sure you can reproduce this issue using the latest released version of Microsoft.Graph or Microsoft.Graph.Beta.
- Please search the existing issues to see if there has been a similar issue filed.
- For issues related to authentication and service errors, please refer to our troubleshooting guide. For service issues, please open a question at https://developer.microsoft.com/graph/support.
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:
- Select a channel with more than a couple of hundred messages.
- Run [array]$ChannelMessages = Get-MgTeamChannelMessage -TeamId $Team.Id -ChannelId $SelectedChannel.Id -All
- 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:[email protected]"
},
"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' }
An example:
Start fetching messages : Sunday 11 February 2024 11:20:31 End fetching messages: Sunday 11 February 2024 11:56:10
$channelmessages.count 3516
36 minutes to fetch 3,516 messages with Get-MgTeamChannelMessage is very slow...