Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11571

List throttling issue while using rowlimit

$
0
0

Hi

We have a dotnet application on Sharepoint 2010. Currently the ListViewThreshold is set to 100,000. I am trying to change the code so as to bring it back to 5000. Now during one operation I try to find the count of a list(uses CAML as well. Earlier, I was fetching all the list items(only ID field) and returned the count.

Now I am inplementing a way to fetch the data in batches. This works when the CAML query is empty.

But if I try to filter the list using CAML, the code is working fine while using a console application but hits the 'Query was throttled' roadblock while running in the application. I am not able to understand the issue.

The code I am using is:

Moreover, I have a doubt:

1. If I have set the threshold to 5000 and I querying the list containing 50,000 items. Does the columns used in Where query need to be indexed?

Any other way in which I can fetch this data without hitting these throttling roadblocks?

SPQuery query = new SPQuery()
                    {
                        Query = whereQuery,
                        ViewFields = "<FieldRef Name='ID'/>"
                    };
                    SPListItemCollection spListItems;
                    bool firstAttempt = true;
                    int itemCount = 2000;
                    int totalCount = 0;
                    bool countNotFinished = true;
                    string pagingInfo = string.Empty;
                    while (countNotFinished)
                    {
                        query.ViewFields = "<FieldRef Name='ID'/>";
                        query.RowLimit = 2000; // Only select the top 2000.
                        StringBuilder sb = new StringBuilder();
                        sb.Append(query.Query);
                        // To make it order by ID and stop scanning the table, specify the OrderBy override attribute.
                        sb.Append("<OrderBy Override='TRUE'><FieldRef Name='ID'/></OrderBy>");
                        //.. Append more text as necessary ..
                        query.Query = sb.ToString();
                        if (firstAttempt)
                        {
                            spListItems = spList.GetItems(query);
                            firstAttempt = false;
                            totalCount = spListItems.Count;
                            result = totalCount;
                            if (result < 2000)
                            {
                                countNotFinished = false;
                                continue;
                            }
                            pagingInfo = spListItems.ListItemCollectionPosition.PagingInfo;
                        }
                        else
                        {
                            SPListItemCollectionPosition pos = new SPListItemCollectionPosition(pagingInfo);
                            query.ListItemCollectionPosition = pos; //page info
                            spListItems = spList.GetItems(query);
                            itemCount = spListItems.Count;
                            totalCount = totalCount + itemCount;
                            result = totalCount;
                            if (itemCount < 2000)
                                countNotFinished = false;
                        }
                    }


Viewing all articles
Browse latest Browse all 11571

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>