Skip to content

Fix feed cache: needs_update ignored the feed timeout - #15

Open
deodorhunter wants to merge 1 commit into
masterfrom
fix-needs-update-minutes
Open

deodorhunter wants to merge 1 commit into
masterfrom
fix-needs-update-minutes

Conversation

@deodorhunter

Copy link
Copy Markdown

Problem

The RSS mixer's in-memory feed cache never worked: every call to @rss_mixer_data downloaded every configured feed again, synchronously, in the request thread. The per-feed timeout (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_update computed now = time() / 6, but _retrieveFeed stores _last_update_time_in_minutes = time() / 60. Today:

  • last_update_time_in_minutes + timeout ≈ 1.75e9 / 60 + 100 ≈ 2.9e7
  • now ≈ 1.75e9 / 6 ≈ 2.9e8

So last_update_time_in_minutes + timeout < now was always True, and update() fetched the feed again every time.

Fix

One-character fix: time() / 6 → time() / 60, the same unit update() and _retrieveFeed() already use. No other code changes.

Tests

New tests in tests/test_rss_mixer.py:

  • RSSMixerFeedCacheTest.test_needs_update_respects_timeout: patches rss_mixer.time to 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: calling update() again within the timeout does not call requests.get; calling it after the timeout fetches again.
  • RSSSMixerTest.test_feeds_are_cached_between_requests (functional): two calls in a row to @rss_mixer_data for the same block make exactly one requests.get per 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

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>
@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 39265282121

Warning

No base build found for commit 166d5ac on master.
Coverage changes can't be calculated without a base build.
If a base build is processing, this comment will update automatically when it completes.

Coverage: 71.429%

Details

  • Patch coverage: 1 of 1 lines across 1 file are fully covered (100%).

Uncovered Changes

No uncovered changes found.

Coverage Regressions

Requires a base build to compare against. How to fix this →


Coverage Stats

Coverage Status
Relevant Lines: 434
Covered Lines: 310
Line Coverage: 71.43%
Coverage Strength: 2.14 hits per line

💛 - Coveralls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants