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 zero follower page case #9363

Conversation

pidgezero-one
Copy link
Contributor

@pidgezero-one pidgezero-one commented May 29, 2024

Closes #9283 (cont'd)

  • Fixes max page validation in the case of zero followers/following

Technical

  • Added max page calculation to _validate_follows_page to contain all of the page validation logic in one place. The output can only be between a minimum page number (1) and ceil(hits / pagesize). Therefore the offset, page - 1, can never be below zero.
  • I've added an extra safeguard to floor offset to zero as well. This doesn't do much in the context of this PR since the output of the validation function should never go below 1, but it's there in case the validation function ever changes, or anything along those lines. I thought about adding an offset validation check further upstream but ultimately I think it should be the consumer function's job to make sure it's passing correct information to the DB interface.

Testing

I repeated my tests from #9323 and #9361. I inserted 25 following and 26 follower records, and then deleted them to test the empty list case.

Screenshot

I redid all of my tests just in case.

Following - 25 total, only one possible page:
image
The output is identical with an invalid page query param (http://localhost:8080/people/openlibrary/following?page=100, http://localhost:8080/people/openlibrary/following?page=-1, http://localhost:8080/people/openlibrary/following?page=0, http://localhost:8080/people/openlibrary/following?page=aaaaa) and with a valid one (http://localhost:8080/people/openlibrary/following?page=1).

Followers - 26 total, 2 possible pages:
No page param specified in the URL:
image
The output is identical with an invalid page query param (http://localhost:8080/people/openlibrary/followers?page=-1, http://localhost:8080/people/openlibrary/followers?page=0, http://localhost:8080/people/openlibrary/followers?page=qqqqqqqqq) and with a valid one (http://localhost:8080/people/openlibrary/followers?page=1).

Page 2, selected by pagination UI:
image
The output is identical with an invalid page query param (http://localhost:8080/people/openlibrary/followers?page=4932930580).

No followers:
image
The output is identical with an invalid page query param (http://localhost:8080/people/openlibrary/followers?page=100, http://localhost:8080/people/openlibrary/followers?page=-1, http://localhost:8080/people/openlibrary/followers?page=0, http://localhost:8080/people/openlibrary/followers?page=wdasfresfmkdmb) and with a valid one (http://localhost:8080/people/openlibrary/followers?page=1).

Results are the same incognito.

Stakeholders

@mekarpeles

Attribution Disclaimer: By proposing this pull request, I affirm to have made a best-effort and exercised my discretion to make sure relevant sections of this code which substantially leverage code suggestions, code generation, or code snippets from sources (e.g. Stack Overflow, GitHub) have been annotated with basic attribution so reviewers & contributors may have confidence and access to the correct context to evaluate and use this code.

@pidgezero-one
Copy link
Contributor Author

Hopefully this is the last one I'll need to do! Sorry about all the followup PRs.

@github-actions github-actions bot added the Priority: 2 Important, as time permits. [managed] label May 29, 2024
@pidgezero-one pidgezero-one changed the title fix 0 page case May 29, 2024
@mekarpeles mekarpeles added the On testing.openlibrary.org This PR has been deployed to testing.openlibrary.org for testing label May 30, 2024
@mekarpeles mekarpeles merged commit 112cf14 into internetarchive:master May 30, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
On testing.openlibrary.org This PR has been deployed to testing.openlibrary.org for testing Priority: 2 Important, as time permits. [managed]
2 participants