pnpcore
pnpcore copied to clipboard
FR - Change List GetById to use Items(ID) Endpoint
Category
- [x] Feature request
Describe the feature
I've been fighting a fighting with a lookup threshold issue between 2 identically configured list (this is a configuration problem, not a problem with PnP.Core)
I had code something like the following:
list.Items.GetByIdAsync(listItemId, x => x.All)
This exposed my configuration issues. However, I noticed if I did something like this:
var listItem = await list.Items.GetByIdAsync(listItemId, x => x.Id);
await listItem.EnsurePropertiesAsync(x => x.All)
It worked.
Looking at the rest calls, the first example generated a rest call that uses a filter:
_api/web/lists(guid'<<GUID>>')/items?$select=Id%2c*&$filter=Id+eq+25&$top=1
but the second did this:
list.Items.GetByIdAsync:
_api/web/lists(guid'<<GUID>>')/items?$select=Id&$filter=Id+eq+25&$top=1
listItem.EnsurePropertiesAsync:
_api/web/lists/getbyid(guid'<<GUID>>')/items(25)?$select=Id%2c*
So it seems that, if you have a list with more than 12 managed metadata fields (which have hidden lookup columns), if you try to load everything with a List.GetById call, it'll fail because of whatever underlying code path SPO uses.
However, ListItem.EnsureProperties follows a different path and will happily load all the data.
Describe the solution you'd like
Use the second method /items(<ID>)
instead of /items?filter=Id+eq+<ID>&$top=1
when calling the GetById methods.
Alternatively, it would be nice if we issued our own ApiRequest to project the results into the underlying internal ListItem implementation, or have a GetByRequest or something where we could pass our own ApiRequest?