Forum Discussion
Unexpected Multiple Requests from Power BI Connector
- 1 year ago
Hey v-kpoloju-msft,
priorities shift at work this week, so I didn't have time yet to look into your suggestions. Hope I will find some time next week to look into Diagnostics.Cache.
Api.Folder doesn't look poosible at this point, but maybe later.
Disabling the preview didn't change anything for me regarding the number of requests. But since I already reduced requests at that point (and I don't have controll over everyone who uses the connector to turn that option off) I don't think that's helping.
Sorry again for the delay and thanks again for all the help and input!
Regards,
Scheißy
Hey Scheißy ,
It seems that the authorization request is being called multiple times because it's inside the MyConnector.Contents function, which gets triggered for each CSV file. To reduce the number of requests:
-
Make the authorization request once and store the token globally (outside the function). Pass this token to all the CSV loads instead of requesting it repeatedly.
Example:
shared token = getAuthResponse()[token] -
Ensure Web.Contents is not called multiple times unintentionally. You can optimize this by making sure the CSV files are loaded only once per request.
-
Since your logs show repeated requests, make sure the file loading is not triggering additional unnecessary requests. Review your debug outputs and check if it's causing multiple calls.
- If your token expires, set up a rule to refresh it only when needed, not on every request.
If you found this solution helpful, please consider accepting it and giving it a kudos (Like) it’s greatly appreciated and helps others find the solution more easily.
Best Regards,
Nasif Azam
- Scheißy1 year agoRegular Visitor
Hey Nasif_Azam!
thank you for your input. I tried your suggestion, but as soon as I try to assign the getAuthResponse result to a shared variable I run into the exception "Microsoft.Mashup.Engine.Interface.UnpermittedResourceAccessException".
PS: it works when I remove the "shared" part for the token variable. But then I can't see any differences in the number of requests.
- Nasif_Azam1 year ago
Super User
Hey Scheißy ,
You are absolutely right Power Query’s engine does not allow Web.Contents to run in shared/global scope, which is why you saw the UnpermittedResourceAccessException. You can try:
1. Use Lazy Evaluation + Let-Caching Inside MyConnector.Contents
Move the getAuthResponse() call once insideMyConnector.Contents, and reuse thetoken within the scope of the same function using a let block:
shared MyConnector.Contents = () => let auth = getAuthResponse(), token = auth[token], profilesData = loadCsvFile("11b567...", token), effectsData = loadCsvFile("116fc8...", token), reportsData = loadCsvFile("02a0a2...", token), source = #table({ "Name", "Data" }, { { "Profiles", profilesData }, { "Effects", effectsData }, { "Status Reports", reportsData } }), navTable = Table.ToNavigationTable(source, { "Name" }, "Name", "Data", "ItemKind", "ItemName", "IsLeaf") in navTable;2. Avoid Nested Diagnostics.Trace Causing Multiple Evaluations
In Power Query, anything inside Diagnostics.Trace may get evaluated more than once (once for value, once for metadata). You can reduce this by moving trace logging after evaluation, or removing trace for heavy operations like getAuthResponse() and loadCsvFile() during testing.
If you found this solution helpful, please consider accepting it and giving it a kudos (Like) it’s greatly appreciated and helps others find the solution more easily.
Best Regards,
Nasif Azam- Scheißy1 year agoRegular Visitor
Hey Nasif_Azam,
thanks again for your suggestions and for the time you take to help me. I really appreciate that 🙂
1. That looks pretty much like the code version I started with. I added all the debugging and loading stuff in trying to reduce the number of requests. When I "go back" to your suggestion I still can see the 4 auth request in my logs.
2. I removed all the debug stuff (not just "turned it off") to see if my Diagontics stuff is doing any harm. Unfortunately I'm still getting 4 auth requests and 24 file requests (8 for each of the 3 files) in my server logs.
Regards,
Scheißy