Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Tally top 80 results exactly and fix "monday" timestamp calculation #1113

Merged
merged 2 commits into from
Feb 1, 2023

Conversation

sarayourfriend
Copy link
Contributor

Fixes

Staci and I noticed two issues while we were deploying the API today:

  1. If the page_size changes (for example to 200), then if we tally the first 4 pages, we'd be tallying the top 800 results, which does not really reflect the intention of the tallying (for seeing the provider density of "top results"
  2. On weeks that include a month boundary, the "monday" date stamp calculation was incorrect. We only found this because we were working on this literally as 00:00 UTC 1 Feb 2023 rolled over from January!

Description

Applies fixes for the above described issues. There are (hopefully) sufficient comments to hopefully describe the approach and intentions as the logic is a bit convoluted.

Testing Instructions

Check out the much expanded unit tests. You can test locally following the process Staci describes here: #1088 (review). However, because local results for any given query do not really have 80 results, you'll need to test without a query or with a * query.

Checklist

  • My pull request has a descriptive title (not a vague title like
    Update index.md).
  • My pull request targets the default branch of the repository (main) or
    a parent feature branch.
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added or updated tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no visible
    errors.

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

@sarayourfriend sarayourfriend added 🟧 priority: high Stalls work on the project or its dependents 🛠 goal: fix Bug fix 💻 aspect: code Concerns the software code in the repository labels Feb 1, 2023
@sarayourfriend sarayourfriend requested a review from a team as a code owner February 1, 2023 00:10
@openverse-bot openverse-bot added this to Needs review in Openverse PRs Feb 1, 2023
@github-actions
Copy link

github-actions bot commented Feb 1, 2023

API Developer Docs Preview: Ready

https://wordpress.github.io/openverse-api/_preview/1113

Please note that GitHub pages takes a little time to deploy newly pushed code, if the links above don't work or you see old versions, wait 5 minutes and try again.

You can check the GitHub pages deployment action list to see the current status of the deployments.

Copy link
Contributor

@AetherUnbound AetherUnbound left a comment

Choose a reason for hiding this comment

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

Wow, nice find! It looks like there's a failing test, I'm able to produce it locally too

results_to_tally = results
elif max_result_depth - page_size < 80:
# Applies when `page_size * page` could land beyond 80, but still
# encompas on _this page_ some results that are below the 80th
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# encompas on _this page_ some results that are below the 80th
# encompass on _this page_ some results that are below the 80th

Copy link
Contributor

@stacimc stacimc left a comment

Choose a reason for hiding this comment

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

The test failure is reproducible for me as well :/

Testing manually the tallies LGTM, though. I tested:

  • "normal" flow by not adjusting page_size and checking the tallies increase correctly after requesting page 1-4 but not after page 5
  • using page_size=7 and checked the tallies increase only for the first 80 values
  • using page_size =100 (after updating MAX_ANONYMOUS_PAGE_SIZE locally 😄) and verified only first 80 on page 1 are counted

@sarayourfriend
Copy link
Contributor Author

Thanks for the reviews. The failing test was due to the fact that I'd accidentally removed the falsey check on results, so None was getting passed to the tallies function. It is fixed now (thank goodness for tests 😅)

Copy link
Contributor

@obulat obulat left a comment

Choose a reason for hiding this comment

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

Perfect timing for deploy :)
LGTM!

Copy link
Member

@dhruvkb dhruvkb left a comment

Choose a reason for hiding this comment

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

Interesting problem and solution, thanks @sarayourfriend!

Openverse PRs automation moved this from Needs review to Reviewer approved Feb 1, 2023
@sarayourfriend sarayourfriend merged commit 4dcb80e into main Feb 1, 2023
Openverse PRs automation moved this from Reviewer approved to Merged! Feb 1, 2023
@sarayourfriend sarayourfriend deleted the add/restrict-by-result-depth-not-just-page branch February 1, 2023 08:00
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
💻 aspect: code Concerns the software code in the repository 🛠 goal: fix Bug fix 🟧 priority: high Stalls work on the project or its dependents
Projects
No open projects
Openverse PRs
  
Merged!
Development

Successfully merging this pull request may close these issues.

None yet

5 participants