简体   繁体   中英

How to reduce the execution time?

Code:

testItemList = testResults.Select(item => project.Store.GetWorkItem(item.TargetId)).ToList();

testItemList is (local variable) List testItemList

testResults is (local variable) WorkItemLinkInfo[] testResults

Totally, 610 work items are present. How to reduce the execution time? As of now, it takes 20 seconds to execute this line of code. How to fine tune the above code, so that to reduce the execution time?

Query query = new Query(project.Store, "Select [Title] From WorkItems", testResults.Select(item => item.TargetId).ToArray());
var car = query.BeginQuery();
//Do something else while awaiting server response...
testItemList = query.EndQuery(car);

Your code does 610 total round trips to the server, and downloads every field of each workitem. This code does a single round trip, and downloads only the Title field.

Note that you will still be able to access every field of each workitem in testitemlist, but each access to a field not included in the original query string will entail another round trip.

http://msdn.microsoft.com/en-us/library/bb130306.aspx

I will take a guess: Store is a WorkItemStore?
What is testResults?

Your linq statement will result in a for loop. Making a new query for each ID. You could possibly speed up the result by using a batch query.
Maybe WorkItemStore.Query(id[], wiql) can speed up. Giving in a list of ids.
You would get a WorkItemCollection then. The "wiql" is query language to specify the fields you want.
Sorry for the short answer. I don't have a TFS at hand to give it a try and post a tested code snippet.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM