Repository navigation
Fix feed cache: needs_update ignored the feed timeout - #15
Open
deodorhunter wants to merge 1 commit into
Open
deodorhunter wants to merge 1 commit into
deodorhunter wants to merge 1 commit into
Conversation
needs_update divided time() by 6 instead of 60, comparing the last update time (minutes) against tenths of minutes, so the check was always true and feeds were re-downloaded on every request. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Coverage Report for CI Build 39265282121Warning No base build found for commit Coverage: 71.429%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsRequires a base build to compare against. How to fix this → Coverage Stats
💛 - Coveralls |
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.
Problem
The RSS mixer's in-memory feed cache never worked: every call to
@rss_mixer_datadownloaded every configured feed again, synchronously, in the request thread. The per-feedtimeout(100 minutes) had no effect. We saw this on a production site: Plone instances fetched an external RSS feed several times per hour, and request worker threads were held up waiting on the remote host.Root cause
RSSMixerFeed.needs_updatecomputednow = time() / 6, but_retrieveFeedstores_last_update_time_in_minutes = time() / 60. Today:last_update_time_in_minutes + timeout≈ 1.75e9 / 60 + 100 ≈ 2.9e7now≈ 1.75e9 / 6 ≈ 2.9e8So
last_update_time_in_minutes + timeout < nowwas alwaysTrue, andupdate()fetched the feed again every time.Fix
One-character fix:
time() / 6→time() / 60, the same unitupdate()and_retrieveFeed()already use. No other code changes.Tests
New tests in
tests/test_rss_mixer.py:RSSMixerFeedCacheTest.test_needs_update_respects_timeout: patchesrss_mixer.timeto control the clock. A feed that was just retrieved does not need an update, still does not at +99 minutes, and does at +101 minutes.RSSMixerFeedCacheTest.test_update_does_not_refetch_within_timeout: callingupdate()again within the timeout does not callrequests.get; calling it after the timeout fetches again.RSSSMixerTest.test_feeds_are_cached_between_requests(functional): two calls in a row to@rss_mixer_datafor the same block make exactly onerequests.getper feed URL.Red before the fix (Plone 6.0.15, Python 3.11):
Total: 18 tests, 3 failures, 0 errors(True is not false,2 != 1,2 != 1). The 15 existing tests passed.Green after the fix:
Total: 18 tests, 0 failures, 0 errors.🤖 Generated with Claude Code