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

2019-07-04 16:28发布

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?

2条回答
我命由我不由天
2楼-- · 2019-07-04 16:44

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.

查看更多
地球回转人心会变
3楼-- · 2019-07-04 16:45

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. :)

查看更多
登录 后发表回答