Unexpected behavior when using FQL

2020-05-01 08:38发布

问题:

Adding the LIMIT option to an FQL causes MORE results to return than without the LIMIT. For an example:

SELECT post_id, actor_id, message,description,type FROM stream WHERE source_id = me()

returns 4 results:

{ "data": [
{
  "post_id": "1458319848_4164228991531", 
  "actor_id": 1458319848, 
  "message": "Oh happy days!", 
  "description": null, 
  "type": 46
}, 
{
  "post_id": "1458319848_4081409841104", 
  "actor_id": 1458319848, 
  "message": "", 
  "description": "Caroline Natan and Or Karlinsky are now friends.", 
  "type": null
}, 
{
  "post_id": "1458319848_4076275592751", 
  "actor_id": 1458319848, 
  "message": "", 
  "description": "Caroline Natan changed her Interested In.", 
  "type": null
}, 
{
  "post_id": "1458319848_4075703458448", 
  "actor_id": 100001179537125, 
  "message": "", 
  "description": null, 
  "type": 237
}]}

But using:

SELECT post_id, actor_id, message,description,type FROM stream WHERE source_id = me() LIMIT 9

returns 5 results:

{"data": [
{
  "post_id": "1458319848_4164228991531", 
  "actor_id": 1458319848, 
  "message": "Oh happy days!", 
  "description": null, 
  "type": 46
}, 
{
  "post_id": "1458319848_4081409841104", 
  "actor_id": 1458319848, 
  "message": "", 
  "description": "Caroline Natan and Or Karlinsky are now friends.", 
  "type": null
}, 
{
  "post_id": "1458319848_4076275592751", 
  "actor_id": 1458319848, 
  "message": "", 
  "description": "Caroline Natan changed her Interested In.", 
  "type": null
}, 
{
  "post_id": "1458319848_4075703458448", 
  "actor_id": 100001179537125, 
  "message": "", 
  "description": null, 
  "type": 237
}, 
{
  "post_id": "1458319848_4069875152744", 
  "actor_id": 100000876758120, 
  "message": "", 
  "description": null, 
  "type": 237
}]}

Of course this DOESN'T MAKE ANY SENSE! Am I missing something here? if so, what? Also I've read this, I didn't see anything regarding the problem described here.

Thanks in advance.

回答1:

The article you linked to actually addresses this issue:

You might notice that the number of results returned is not always equal to the “limit” specified. This is expected behavior. Query parameters are applied on our end before checking to see if the results returned are visible to the viewer. Because of this, it is possible that you might get fewer results than expected.

Which basically means that facebook filters the results after it executes the query.

In your example, in the first query, there's an implicit limit, say 5. Out of these 5 results, 1 is filtered out because of visibility restrictions and you get 4. In the second query, the server gets 10 results, filters 5 of them out based on visibility and returns 5 to you.