Storing Facebook likes locally - Fetching number of likes performance issue

Enberg

New Member
I am building an app using ASP.NET 4.0. I have a table called entries. Entries can be liked via Facebook. I want to implement the ability to sort via likes so I am taking the approach of storing the number of likes for each entry and using that column to order. The problem is the overhead involved in getting the number of likes. I think the method I am using could be improved as right now because fetching data for only 13 entries is taking 4 seconds, which is way too long. I am using the FB graph api and JSON.NET to parse the response. In the following code I have a List of type Entry, I am getting the like url for the entry using an app setting combined with the entries id. This is what I am doing:\[code\] foreach (Entry entry in entries) { int likes; try { // the url that is tied to the entry string url = "http://graph.facebook.com/?ids=" + Properties.Settings.Default.likeUrl + "?id=" + entry.EntryId; //open a WebClient and get the results of the url WebClient client = new WebClient(); Stream data = http://stackoverflow.com/questions/12708718/client.OpenRead(url); StreamReader reader = new StreamReader(data); string s = reader.ReadToEnd(); //parse out the response var json = JObject.Parse(s); //shares are how many likes the entry has likes = Convert.ToInt32(json.First.First.SelectToken("shares").ToString()); } catch (Exception ex) { likes = 0; } } \[/code\]As I said this method is very expensive. If anyone could suggest a better way to do what I am attempting here I would really appreciate the help. Thanks much!
 
Back
Top