1

I have a secondary DataSource with about 23k entries. The User inputs an ID and gets only 1 Dataset back. If I use:

XPathNavigator test = nav.SelectSingleNode("/dfs:myFields/dfs:dataFields/d:SharePointListItem_RW[d:Title = '" + ID + "']", NamespaceManager);

it takes about 8 seconds to return the Node. Is there a better (faster) way?

DanielR
  • 701
  • 2
  • 12
  • 24

1 Answers1

0

You can collect all the SharePointListItem_RW nodes in a Dictionary (key would be the title id and the value would be the node that contains the title as id) at the start of your app..

[Memory consumption would not be an issue here since it would hardly cross 1MB]

Then you can select the particular node by using TryGetValue method of Dictionary

The complexity would be O(1) which is fast

Anirudha
  • 32,393
  • 7
  • 68
  • 89
  • any hints how to put all the nodes into a dictionary? And that is fast? – DanielR Jan 07 '13 at 11:45
  • ok but how to put all SharePointListItem_RW nodes in a Dictionary? – DanielR Jan 07 '13 at 11:46
  • @DanielR check out [this](http://www.dotnetperls.com/dictionary) and [this](http://stackoverflow.com/questions/6578658/reading-xml-to-dictionary) – Anirudha Jan 07 '13 at 11:56
  • this explains usage of dictionaries. But how should I get all the 23000 nodes into a dictionary in a reasonable time? Or did you mean something completly different? – DanielR Jan 07 '13 at 12:13
  • great but is this also available in VSTA (C# 2005)?? – DanielR Jan 07 '13 at 12:19
  • Yes, it is. Dictionary dict = new Dictionary(); foreach(XmlNode n in nav.SelectSingleNode("/dfs:myFields/dfs:dataFields/d:SharePointListItem_RW", NamespaceManager)){ dict.Add(n.SelectSingleNode(d:Title, NamespaceManager).Value, n); } – JLRishe Jan 08 '13 at 07:58
  • In reality, though, you should probably be filtering the data source when you query it. I don't suppose you need all 23,000 of those records at once, do you? – JLRishe Jan 08 '13 at 07:59