Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get Next and Previous should not use cursors #623

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mbvb1223
Copy link
Contributor

@mbvb1223 mbvb1223 commented Jan 7, 2025

https://developers.facebook.com/docs/graph-api/results/

  • next : The Graph API endpoint that will return the next page of data. If not included, this is the last page of data. Due to how pagination works with visibility and privacy, it is possible that a page may be empty but contain a next paging link. Stop paging when the next link no longer appears.
  • previous : The Graph API endpoint that will return the previous page of data. If not included, this is the first page of data.

===
For example: If my cursor has total 4 items (default limit is 25)

$cursor->setDefaultUseImplicitFetch(true);
foreach ($cursor as $item) {
    $data[] = $item->exportAllData();
}

So I need to make one request to get the cursor with 4 items. The current code getNext() will always return a URL and

public function fetchAfter() {
    $request = $this->createAfterRequest();
    if (!$request) {
      return;
    }

    $this->appendResponse($request->execute());
  }

fetchAfter() will execute one more request and return an empty data. So, we need to make 2 requests to get for only 4 items.

So if $content['paging']['next'] is empty, we should return null and do not need to make more requests

@mbvb1223
Copy link
Contributor Author

mbvb1223 commented Jan 7, 2025

@stcheng st could you please take a look if you have time. Thanks!

@mbvb1223 mbvb1223 changed the title Get Next and Previous should not using cursors Get Next and Previous should not use cursors Jan 7, 2025
@facebook-github-bot
Copy link

@stcheng has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants