Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Too many SPO REST calls required to use LoadListDataAsStream( ) #1383

Closed
1 task done
wizofaus opened this issue Feb 6, 2024 · 3 comments
Closed
1 task done

Too many SPO REST calls required to use LoadListDataAsStream( ) #1383

wizofaus opened this issue Feb 6, 2024 · 3 comments
Assignees
Labels
question Further information is requested

Comments

@wizofaus
Copy link

wizofaus commented Feb 6, 2024

Category

  • Bug

Describe the bug

Currently due to the way PnPContextFactory.CreateAsync() works (always issuing at least 1 SPO REST call, 2 in my case), and the fact that I can't see how to get necessarily field data back from LoadListDataAsStreamAsync, I have to issue 4 separate SPO REST calls just to get the info I need from a library. With any sort of latency this can add up to a significant delay (500ms+).

Repro steps

Write minimal code for obtaining an IList from the PnP.Core library (e.g. PnPContextFactory.CreateAsync( ), context.Web.Lists.GetByIdAsync( )) then calling IList.LoadListDataAsStreamAsync() and monitor the number of HTTP calls issued and the time taken for them to execute fully.

Expected behavior

Ideally only a single SPO REST call is issued, two at most. Even caching previous results I can't really see how to reduce it from 4, and I'm not sure if it's sensible/safe to cache PnPContext / IList etc.

Environment details (development & target environment)

  • SDK version: 1.11.0
  • OS: Windows 10
  • SDK used in: ASP.Net (Core) Web app
  • Framework: .NET Core v8.0
  • Browser(s): N/A
  • Tooling: Visual Studio 2022
  • Additional details: The more context you can provide, the easier it is (and therefore quicker) to help.

Additional context

Thanks for your contribution! Sharing is caring.

@jansenbe jansenbe added the question Further information is requested label Feb 12, 2024
@jansenbe
Copy link
Contributor

@wizofaus : interesting ask. The fact that there are 2 REST calls when the context is created is related to batching, initially we had one batch call to load all the initialization data, we however split that to one interactive call and one batch call as with the interactive call we do get the correct site URL casing, which is required for batching to work.

Did you check this option: https://pnp.github.io/pnpcore/using-the-sdk/basics-context.html#loading-additional-iweb-and-isite-properties-when-creating-a-pnpcontext ? It will allow you to also load the web's lists as part of that second batch call.

As possible future change we might enable the single batch call system again as something optional, the one using it however has to provide the URL is the exact casing...would this help you or are you dependent on URL's entered manually (with the risk of wrong casing being used)?

@wizofaus
Copy link
Author

wizofaus commented Feb 12, 2024 via email

@jansenbe jansenbe self-assigned this Feb 22, 2024
jansenbe added a commit that referenced this issue Feb 22, 2024
…undtrip to SharePoint if the valid site casing is used in combination with `PnPContextOptions.SiteUriCasingIsCorrect` #1383
@jansenbe
Copy link
Contributor

@wizofaus : I've implemented support for this, using the PnPContextOptions you can explain you're using valid casing and then the initialization will be done using a single batch request to SharePoint loading the needed web/site data in one go.

using (var context = await pnpContextFactory.CreateAsync("SiteToWorkWith", 
                                                        new PnPContextOptions()
                                                        {
                                                            SiteUriCasingIsCorrect = true
                                                        })
    )
{
    // Use the context
}

See also https://pnp.github.io/pnpcore/using-the-sdk/basics-context.html.

This feature will be part of the next nightly build. Closing this issue now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants