[APIView] WI-5: Retention Event Handlers & Background Purge
- Dominant language
- C#
- Stars
- 135
- Forks
- 260
- Avg merge
- 3d 1h
- Merged PRs (30d)
- 144
Description
## Goal
Replace ad-hoc deletion heuristics (`AutoArchiveAPIRevisions`, `AutoPurgeAPIRevisions`, `CleanupPullRequestData`) with unified `RetainUntil`-based retention policy from §4.8.
**Area:** Retention · **Depends on:** WI-3, WI-4 · **Stable alone:** ✅ Yes
## Deliverables
### Event handlers
Add methods to `APIVersionsManager`:
| Method | Trigger | Action |
|---|---|---|
| `OnStableVersionReleased` | Stable version released | Set `RetainUntil` on superseded Preview (90d) and graduated RollingPrerelease (30d). Enforce always-retain invariants. |
| `OnRevisionSuperseded` | New revision replaces prior | Set `RetainUntil = now + 30d` on superseded revision if not latest/approved/released |
| `OnPRClosed` | PR merged or closed | Set `RetainUntil` based on merged (60d) vs closed (30d). Promoted PRs: clear `RetainUntil`. |
| `OnVersionApprovedOrReleased` | Version approved/released | Clear `RetainUntil → null` (retain indefinitely) |
### Background purge job
Replace retention logic in `ReviewBackgroundHostedService`:
1. **Version-level purge:** Query versions where `RetainUntil < now`. Cascade-delete: revisions, comments, blobs, then version.
2. **Revision-level purge:** Query revisions where `RetainUntil < now`. Delete blobs, then hard-delete document.
3. **Rate limiting:** 500ms inter-deletion delay.
Old `AutoArchiveAPIRevisions` and `AutoPurgeAPIRevisions` retired once fully deployed. Both old and new paths coexist behind feature flag during transition.
### Tests
- `RetentionPolicyTests.cs` — All event handler scenarios; invariant enforcement; cascade deletion
- `ReviewBackgroundHostedServiceTests.cs` — Purge loop scheduling; rate limiting; empty result handling
### Documentation
Update `docs/overview.md` §4e (Background Services) to describe unified retention purge.
Contributor guide
Research direction
Start with APIVersionsManager and the existing retention paths AutoArchiveAPIRevisions, AutoPurgeAPIRevisions, and CleanupPullRequestData, then read ReviewBackgroundHostedService. Use RetentionPolicyTests.cs and ReviewBackgroundHostedServiceTests.cs to cover the listed event, cascade-purge, scheduling, rate-limiting, and empty-result scenarios. Update docs/overview.md §4e when the unified purge and transition behavior are complete.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api, backend, database
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100