fix(stats): compute week/month cutoffs at call time (#13789) - #13808
Open
LalitNarayanYadav wants to merge 1 commit into
Open
LalitNarayanYadav wants to merge 1 commit into
LalitNarayanYadav wants to merge 1 commit into
Conversation
Collaborator
|
Thanks for the PR, @LalitNarayanYadav! 🤖 A reviewer has been assigned for an initial pass. PR triage checklist (maintainers / Pierre)
Note This comment was automatically generated by Pierre, Open Library's PR first-touch assistant, on behalf of @mekarpeles. This is NOT a code review or sign-off. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #13789
fix: week/month stats cutoffs are now computed when used, not at import time.
Technical
The constants
DATE_ONE_DAY_AGO,DATE_ONE_WEEK_AGO,DATE_ONE_MONTH_AGOandDATE_ONE_YEAR_AGOinutils/dateutil.pywere evaluated once when the module loaded, so a long-running server kept using its start date.I turned them into functions (
date_one_week_ago()etc.) and updated every place that used them: thesummary()methods incore/andreading_log_leaderboardinviews/loanstats.py. The month calculation is unchanged; I'm leaving the month-length question for a separate issue.Testing
Added
test_date_cutoffs_are_computed_at_call_timeinopenlibrary/utils/tests/test_dateutil.py. It moves a fake clock forward a month and checks the cutoffs follow it; it fails on the old code.I ran
pytest openlibrary/utils/tests/test_dateutil.pylocally (6 passed). I did not run the full suite or load the stats page, so I'm relying on CI for those.Screenshot
N/A (no UI change)
Stakeholders