FAcebook performance problems.

some problem left on faceBook stuff:

Hi, there. ..i havent done facebook development for a while, but still some problmes saving on that areas.

on my facebook web application,  we are goin to retrieve the info and grab the info from webserives.  but the performance porblems still existes and may occur huge problems which may disappoint general users.  Ive been tested lots of my current web application:

since, in our postback , page load method.

IList<user>= fbservice.api.getUserobject(); this will take huge amount time on loading and waiting websericve from the Facebook service.
But the damned things about the facebook platform is the FQL query can not retrieve the info from multi-tables in facbook tabase.

once i got the qurey result of links, i probably can only get the info about the owner, links , some pictures .. here, the owner is equal uid in user tables.

So, its hard to replace the owner name to the real owner.id, which is good for user get relevent information.

in my earlier codes::

foreach (user user1 in friends)

{

foreach (link lk in linklist)

{

if (lk.Owner.ToString() == user1.uid.ToString())

{

lk.Owner = user1.name;

}

}

}

Using this way..i got 50 firends there and will get 10 links here…i will loop 500 times and just taking too much time about 2o sec..in my testing stage.

Rayn just provid a good way to handle this kinda data convertion process- using dictionary. and fill the data into the sesstion["xxx"] object and retrieve the data using session["xxx"], instead of loading and grabbing infromation all the time.

Dictionary(TKeyTValue) Class:

The Dictionary(TKey, TValue) generic class provides a mapping from a set of keys to a set of values. Each addition to the dictionary consists of a value and its associated key. Retrieving a value by using its key is very fast, close to O(1), because the Dictionary(TKey, TValue) class is implemented as a hash table.  — msdn

cause the facebook.schema already got the user class there, it seems i dont need to create a new claas to handle the attributes and perpoties stuff.

The things Ryan told me to do is greate useful:

IList<user> friends = fbService.API.friends.getUserObjects();

Dictionary<long?, user> mdic = new Dictionary<long?, user>();

foreach (user user1 in friends)

{

mdic.Add(user1.uid, user1);

}

Session["anything"] = mdic;

and on my tab control template using stuff and replace the owner to the dictionary lookup result::

(session["anything"] as Dictionary<long?, user>)[ Convert.Toint64( lk.owner)].name.Tostring().

it suppose to shown username there.

another great things for the dictionary and session[] and application[] is you can only get the data once, and save them and fill them into session or application object. and you can call them in different pages and will saving lots of time on loading and waitting for response time for general users.  the only thing u neeed to do is to make sure the seesion is still alive…

and think about that, if you got lots of users using ur site. saving the data into application object is aslo greate. cause friends list may be repeat somehow and u can retrieve the application object much faster…

~ by kimialex92 on 2009/04/09.

Leave a Reply