running a “join” like FQL for getting a user name

2019-07-04 16:12发布

问题:

I am trying to get all the posts in the news feed for a specific user using FQL using the following FQL statement:

SELECT post_id, actor_id, target_id, message, created_time, updated_time, permalink, description 
FROM stream 
WHERE filter_key in 
(SELECT filter_key FROM stream_filter WHERE uid=me() AND type='newsfeed')
AND is_hidden = 0 AND created_time > xxx

But i need the user name (first and last names) of every user that made a post that appears in my news feed (the user name that is matching the "actor_id").

It seems i cannot user a join operation in FQL and i would not want to run a select operation for every post in my news feed (can be dozens of extra calls in the form of: "SELECT uid, name FROM user WHERE uid=").

Is there a way to overcome this?

回答1:

You need to use a FQL Multi-Query to fetch two result-sets: the first from stream & the second from user. Then for each result in the first one, look up actor_id in the second.



回答2:

Your query should look like this :

 NSString *query =
    @"{"
    @"'friends':'SELECT post_id,actor_id,target_id,message,created_time, likes, comment_info FROM stream WHERE source_id IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND created_time > 1  ORDER BY created_time DESC LIMIT 50',"
    @"'friendinfo':'SELECT uid, name, pic_square FROM user WHERE uid IN (SELECT actor_id FROM #friends)',"
    @"}";

Hope this will help. :)