1

I am using the code below to retrieve data from different lists, but I see that it is slower than Content Search Web part. The returned rows are the same 28 in total, but it takes more time csom to display the results. Imagine if I have 1000 items, it will take forever.

My questions are, what can I do to improve the performance and how can I measure the time it took to return the results?

I thought of using this class System.Diagnostics.Stopwatch(), but it does not exist in javascript or does it?

One thing though, I can't use Content Search Web part because, we have SharePoint standard on our production server.

SP.SOD.executeFunc('sp.js', 'SP.ClientContext',function(){


SP.SOD.executeFunc('sp.search.js','Microsoft.SharePoint.Client.Search.Query.KeywordQuery',function (){
            var queryText = "ContentTypeId:0x010066FA3DE3E334C841B418C82CC475A227*";
                var clientContext = new SP.ClientContext("http://dev:5050");
                var contextSite = clientContext.get_site();
                var keywordQuery = new Microsoft.SharePoint.Client.Search.Query.KeywordQuery(clientContext); 
                keywordQuery.set_queryText(queryText); 
                keywordQuery.set_rowLimit(500);
                keywordQuery.set_trimDuplicates(false);
                var searchExecutor = new Microsoft.SharePoint.Client.Search.Query.SearchExecutor(clientContext);  
                var results = searchExecutor.executeQuery(keywordQuery); 
                clientContext.executeQueryAsync(onQuerySuccess, onQueryError);

                function onQuerySuccess()
                {
                    var oTable = $('#articlesOverview').DataTable({
                        "iDisplayLength": 25,
                        "iTotalRecords": 57,
                        "iTotalDisplayRecords": 57,
                        "bDestroy": true,
                        "bProcessing":true,
                        "aaData":results.m_value.ResultTables[0].ResultRows,
                        "aoColumns":[
                        {
                            "mData":"Title"
                    },
                        {"mData":"Path","visible": false},              
                        ]
                    });


                }

                function onQueryError(sender, args)
                {
                    alert("call failed. Error: " + args.get_message());
                }
        });
    });  
1
  • Remote code is always going to be slower than an OOB web part that executes directly on the server. Aug 28, 2015 at 19:48

1 Answer 1

1

You can measure the time by using a global variable like this:

window.StartTime = new Date()

And in your onQuerySuccess() console.log("The query returned after" + ((new Date() - window.StartTime) / (60*60)) + " seconds")

You could try to use REST based api for better performance... https://msdn.microsoft.com/de-de/library/office/JJ163876.aspx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.