Skip to content
This repository has been archived by the owner on Jul 6, 2022. It is now read-only.

fix: no questions remaining fixed with pagination #416

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

sumana2001
Copy link
Collaborator

@sumana2001 sumana2001 commented Apr 5, 2022

What

  • Instead of checking if the total no. of questions in the buffer is less than 10, we check if the total number of questions in the entire database is less than 10 to add no questions remaining
  • Used pagination such that whenever the question buffer has only 1 question left, it will load questions of the next page number

Closes #394

Screenshot

Currently deployed version:
Link: https://hunger.openfoodfacts.org/questions?country=en%3Aunited-states&type=brand&sorted=true

Screen.Recording.2022-04-06.at.1.28.24.AM.mov

Fix:

Screen.Recording.2022-04-06.at.1.31.08.AM.mov

Fixes bug(s)

Copy link
Member

@alexfauquette alexfauquette left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pagination is a bit more complex than. You should handle

  • page increment
  • page out of range
  • reset page when new search values

I think the easiest way is to put all the logic in loadQuestions method

Notie that you do not always need to incread page, because if the user answer questions this questions are replaced by new ones in the next API call

Comment on lines 200 to 202
if (newBuffer.length == 1) {
this.page += 1;
}
Copy link
Member

@alexfauquette alexfauquette Apr 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why waiting to reach 1?

@sumana2001
Copy link
Collaborator Author

Notice that you do not always need to increase page, because if the user answers questions these questions are replaced by new ones in the next API call

Hey @alexfauquette, I am not sure what you meant by this. Could you elaborate on when I should increase the page number?

@sumana2001
Copy link
Collaborator Author

  • page out of range

@alexfauquette While trying to add the out of range checks, I came across this error and am not able to figure out why it is happening. In the following URL,
https://hunger.openfoodfacts.org/questions?type=brand&sorted=true
it is showing no questions remaining even though there are more than 90000 questions left. But when I did console log in localhost, I found the URL it is sending a request to which is
https://robotoff.openfoodfacts.org/api/v1/questions/popular?count=10&lang=en&insight_types=brand
When you open the link you can see the questions actually there.

Could you please help me understand why the questions are not getting displayed in the hunger games website? I am attaching some screenshots for reference
Screenshot 2022-05-17 at 12 15 35 PM
Screenshot 2022-05-17 at 12 15 51 PM

@alexfauquette
Copy link
Member

For the question about "out of range but server send ack questions". I think it is related to the fact non of those questions contains a source_image_url field

See #394 (comment)

About when to increase the page number:

Increasing page number

I assume that as long as robotoff.questions(..., page) returns question that have never been seen, nor are in the buffer, we can stay on this page. Products are renewed because the user is answering questions, wich decrease the stack

Reseting page number

When the filter parameters are modified, the page should go back to the beginning

Disabling pagination

If the sorting is random, it is not necessary to increase the page

No remaining

Instead of the following dummy verification I did, we could chack when page is the last one (count/pageSize >= page) after fetching the page, add the NO_QUESTION_LEFT to the batch because after this page there is not more questions

https://github.com/alexfauquette/openfoodfacts-hungergames-1/blob/23ca2a0797e914497f04ef360f5e0a48a7944f46/src/views/QuestionView.vue#L238-L243

@sumana2001
Copy link
Collaborator Author

sumana2001 commented May 17, 2022

Hey @alexfauquette
Thank you for dividing the issue into smaller parts and explaining each of them. It really made the entire issue very clear. I tried implementing all the pointers. Please have a look and let me know the changes. Here are the pointers:

  • Reseting page number
  • Disabling pagination
  • Increasing page number
  • No remaining questions
  • Out of range

Copy link
Member

@alexfauquette alexfauquette left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did a quick review. I will have more time to do a better one during the week

src/views/QuestionView.vue Show resolved Hide resolved
src/views/QuestionView.vue Outdated Show resolved Hide resolved
}
return;
if (this.remainingQuestionCount / count + 1 < this.page) {
this.page = 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are out of range you do not want to set page back to 0, but to add a No_Remaining_Questions

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added that condition if somehow the user reaches some page out of range. No remaining questions is added only if the number of total questions remaining becomes less than the page size i.e. 10

src/views/QuestionView.vue Outdated Show resolved Hide resolved
src/views/QuestionView.vue Outdated Show resolved Hide resolved
src/views/QuestionView.vue Outdated Show resolved Hide resolved
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
Status: Pull Request
Development

Successfully merging this pull request may close these issues.

Hunger Games tells there are no questions left (when there actually is)
2 participants