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

fix execution of execute and load_next_page method #587

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

deepprajapati18
Copy link

There is a bug while working with Facebook request API, that is not giving all the elements as it is returning 25 elements. So by checking the execute method of the FacebookRequest, I notice one thing that, it is calling only for the first paginated elements and the default returning limit is 25 so It is returning only first page data, and will not check for the next page.

So in the execute method of FacebookRequest, there is a method called load_next_page which is the method of the Cursor, which is calling the graph API but it will run only for the first time and it will not check the next page of data. So I updated it like: add a while loop and check the status of the load_next_page and store the result in the status. So if the status will True then It will check the re-execute the load_next_page, which will call the next page graph API as on every execution of load_next_page, URL-PATH which is self._path, will update to next page URL.

And this process will continue until there is no next Page URL. If there is not Next Page URL then self._finished_iteration from Cursor will set to True and when the load_next_page will run again then it first check if self._finished_iteration then return False.

And we will store this value in the status which is in the loop of the execute method of FacebookRequest. So when the status will False break the loop and continue the process as it is already there.

There is a bug while working with Facebook request API, that is not giving all the elements as it is returning 25 elements. So by checking the execute method of the FacebookRequest, I notice one thing that, it is calling only for the first paginated elements and the default returning limit is 25 so It is returning only first page data, and will not check for the next page. 

So in the execute method of FacebookRequest, there is a method called load_next_page which is the method of the Cursor, which is calling the graph API but it will run only for the first time and it will not check the next page of data. So I updated it like: add a while loop and check the status of the load_next_page and store the result in the status. So if the status will True then It will check the re-execute the load_next_page, which will call the next page graph API as on every execution of load_next_page, URL-PATH which is self._path, will update to next page URL.

And this process will continue until there is no Next Page URL. If there is not Next Page URL then self._finished_iteration from Cursor will set to True and when the load_next_page will run again then it first checks if self._finished_iteration then return False.

And we will store this value in the status which is in the loop of the execute method of FacebookRequest. So when the status will False break the loop and continue the process as it is already there.
@facebook-github-bot
Copy link

Hi @deepprajapati18!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@thatalfredh
Copy link

There is a bug while working with Facebook request API, that is not giving all the elements as it is returning 25 elements. So by checking the execute method of the FacebookRequest, I notice one thing that, it is calling only for the first paginated elements and the default returning limit is 25 so It is returning only first page data, and will not check for the next page.

So in the execute method of FacebookRequest, there is a method called load_next_page which is the method of the Cursor, which is calling the graph API but it will run only for the first time and it will not check the next page of data. So I updated it like: add a while loop and check the status of the load_next_page and store the result in the status. So if the status will True then It will check the re-execute the load_next_page, which will call the next page graph API as on every execution of load_next_page, URL-PATH which is self._path, will update to next page URL.

And this process will continue until there is no next Page URL. If there is not Next Page URL then self._finished_iteration from Cursor will set to True and when the load_next_page will run again then it first check if self._finished_iteration then return False.

And we will store this value in the status which is in the loop of the execute method of FacebookRequest. So when the status will False break the loop and continue the process as it is already there.

This was amazing, thank you!

@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

2 similar comments
@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@deepprajapati18
Copy link
Author

There is a bug while working with Facebook request API, that is not giving all the elements as it is returning 25 elements. So by checking the execute method of the FacebookRequest, I notice one thing that, it is calling only for the first paginated elements and the default returning limit is 25 so It is returning only first page data, and will not check for the next page.
So in the execute method of FacebookRequest, there is a method called load_next_page which is the method of the Cursor, which is calling the graph API but it will run only for the first time and it will not check the next page of data. So I updated it like: add a while loop and check the status of the load_next_page and store the result in the status. So if the status will True then It will check the re-execute the load_next_page, which will call the next page graph API as on every execution of load_next_page, URL-PATH which is self._path, will update to next page URL.
And this process will continue until there is no next Page URL. If there is not Next Page URL then self._finished_iteration from Cursor will set to True and when the load_next_page will run again then it first check if self._finished_iteration then return False.
And we will store this value in the status which is in the loop of the execute method of FacebookRequest. So when the status will False break the loop and continue the process as it is already there.

This was amazing, thank you!

You're welcome. @thatalfredh

@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@VictorValar
Copy link

was this ever fixed?

@GoooGu
Copy link

GoooGu commented Dec 6, 2023

This actually isn't an issue as long as you iterate the returned cursor from execute(). The Cursor object will load_next_page() for you if the queue is empty.

@GoooGu
Copy link

GoooGu commented Dec 6, 2023

Now the real problem is how to make this load_next_page() faster. If I have 10k ad creatives, how do I fetch all the rows quickly without taking over 80 seconds.

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.

None yet

5 participants