0

SharePoint Rest API taking around 13 seconds to fetch data from List based on some filter conditions. This is making the app slow for the users and they are complaining. Is there a way to make the REST call a bit faster ?

Added the code which calls the REST end point.

enter image description here

function getTasks() {
    return $http({
        method: 'Get',
        url: _spPageContextInfo.webServerRelativeUrl + "/_api/SP.AppContextSite(@target)/web/lists/getByTitle('TasksList')/items?$select=*,ProjectTitle/Title,ProjectTitle/Id,ResponsiblePersons/Id,ResponsiblePersons/Title,Attachments,AttachmentFiles,TaskRequestor/Id,TaskRequestor/Title&$expand=ProjectTitle,ResponsiblePersons,AttachmentFiles,TaskRequestor&$top=9999&@target='" + spContext.hostWebUrl + "'",
        headers: {
            'Accept': 'application/json;odata=verbose',
        }
    });
}
Karthik
  • 241
  • 3
  • 17
  • Please show us some code for a better response. – Ashik Paul Jun 25 '18 at 07:17
  • Try async: true or mention only the required columns instead of "*" in select section – Ashik Paul Jun 25 '18 at 08:29
  • May be Instead of fetching all the items at once, try to fetch the items in small chunks like bunch of 1500 or 2000 and then keep appending the result - refer this link - https://sharepoint.stackexchange.com/questions/217254/rest-to-read-more-than-5000-items-from-document-library/217451#217451 – Rohit Waghela Jun 25 '18 at 18:05
  • this too - http://sympmarc.com/2016/11/30/25696/ – Rohit Waghela Jun 25 '18 at 18:05

3 Answers3

2

If you don't need metadata about the requested list items you could change your header to:

"Accept": "application/json; odata=nometadata"

There is an additional step between 'verbose' and 'nometadata' but the name currently eludes me.

It helped greatly in my case, although it might not make much of a difference in your case with more complex filters. Ususally, I just request more data than I need (ex. all items) and filter in the application/client.

When querying 100,000 complex list items, i got a speed increase of about 50% if metadata is skipped.

  • Thanks for answer. I don't need metadata. But your solution is not working in my case. I have SP2013 on-premise. – Karthik Jul 10 '18 at 12:45
1

When we make a call with the REST API, there is a lot of additional data which we get back in the response. This additional data consists of the metadata and the Hyper Media Controls along with the required JSON data. This makes the payload size of the REST response too big. If you are developing a REST heavy application, then each extra byte of data that travels over the wire to your client adds up and ends up hampering performance. Improving REST API performance you need to explore the changes in the header of rest calls or

Source

Robert Lindgren
  • 24,520
  • 12
  • 53
  • 79
Sunil Sahu
  • 1,768
  • 10
  • 11
0

I am able to improve performance by not requesting item attachments. I am fetching them on demand. The request is now taking only 3.77 seconds to complete.

The modified getTasks function is below:

function getTasks() {
    return $http({
        method: 'Get',
        url: _spPageContextInfo.webServerRelativeUrl + "/_api/SP.AppContextSite(@target)/web/lists/getByTitle('TasksList')/items?$select=*,ProjectTitle/Title,ProjectTitle/Id,ResponsiblePersons/Id,ResponsiblePersons/Title,TaskRequestor/Id,TaskRequestor/Title&$expand=ProjectTitle,ResponsiblePersons,TaskRequestor&$top=9999&@target='" + spContext.hostWebUrl + "'",
        headers: {
            'Accept': 'application/json;odata=verbose',
        }
    });
}

The screenshot showing the time is below: enter image description here

Karthik
  • 241
  • 3
  • 17