Skip to content

feat: purge content of posts past retention window in scheduler - #16

Merged
Devathmaj merged 1 commit into
mainfrom
llm-reddit-db-update
Aug 14, 2026
Merged

feat: purge content of posts past retention window in scheduler#16
Devathmaj merged 1 commit into
mainfrom
llm-reddit-db-update

Conversation

@Devathmaj

Copy link
Copy Markdown
Owner

Description

Long-lived posts accumulate large scraped bodies over time. Since only recent posts are ever surfaced to users, the posts.content column is now nulled out for every post whose created_at is older than settings.content_retention_days (default 7 days). The purge runs on each scheduler loop iteration, so content stays bounded continuously without manual intervention.

A raw UPDATE posts SET content = NULL WHERE created_at < cutoff AND content IS NOT NULL is used on purpose: a Core/ORM update() would also write updated_at = now() via the model's onupdate hook, but this retention job must touch only the content column.

Type of Change

  • Bug fix
  • New feature
  • New source
  • Configuration / settings change
  • Database migration
  • Documentation update
  • Refactor (no functional change)
  • Other:

Affected Components

  • Scheduler / Dispatcher
  • HTTP Policy Layer (http_policy.py)
  • RSS Collector
  • Website Collector
  • Reddit Integration
  • AI Layer (Groq / Gemini)
  • Email Notifications
  • Database / Migrations
  • API / Routers
  • Configuration / Settings

Testing

  • Ran pytest — all tests pass
  • Ran ruff check . && ruff format . — no lint errors
  • Ran python scripts/verify_sources.py — all sources resolve (if sources were added or modified)
  • Added unit tests for new business logic
  • Added integration tests using fixtures or recorded responses (no live network calls)
  • Mocked Reddit API client in all new tests
  • Mocked Groq / Gemini responses in all new tests

Migration

N/A — no schema change; this is application-level cleanup driven by created_at.

Policy Checklist

  • This PR touches one or more policy-sensitive files

If checked, confirm all of the following:

  • robots.txt compliance is preserved — the policy layer is not bypassed or disabled.
  • No default crawl delays have been reduced below 2.0 seconds.
  • Reddit rate limits (100 req/min) and the Responsible Builder Policy are respected.
  • REDDIT_INGESTION_ENABLED=false still collects Reddit via RSS and makes no OAuth calls.
  • No new direct httpx or aiohttp calls exist outside the policy layer.

Explanation:
services/scheduler.py gains one call to purge_expired_post_content(); it performs no network activity and does not alter collection or rate-limit behavior. No changes to http_policy.py, reddit/client.py, or reddit/collector.py.

AI Layer Changes

N/A — no prompt, schema, or provider logic changed.

Additional Notes

  • Runs once per scheduler loop iteration; the loop wakes at the earliest due source, capped at 6 hours (MAX_SLEEP_SECONDS) and 60 s while emails are pending. Idempotent (content IS NOT NULL guard), so frequent re-runs are harmless.
  • Configurable via CONTENT_RETENTION_DAYS (default 7).

@coderabbitai

coderabbitai Bot commented Aug 14, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@Devathmaj, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 46 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 9c14578f-7e52-4eb7-8572-b84fa17861f6

📥 Commits

Reviewing files that changed from the base of the PR and between 9404132 and f995bdf.

📒 Files selected for processing (4)
  • tests/test_retention.py
  • voucherbot/config/settings.py
  • voucherbot/services/retention.py
  • voucherbot/services/scheduler.py

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Devathmaj
Devathmaj merged commit 865447e into main Aug 14, 2026
8 checks passed
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.

1 participant