refactor(api): system/jobs/modules/instances SQL moves behind interfaces - #535
refactor(api): system/jobs/modules/instances SQL moves behind interfaces#535chodeus wants to merge 3 commits into
Conversation
Edit-history, metadata-completeness and library-stats move to sibling modules as mixins; MediaCache keeps its exact class surface (dir() is byte-identical against main) and every import path re-exports unchanged. media_cache.py: 1791 -> 1254 lines. Move-only — each block byte-identical to its origin.
backend/api holds zero raw SQL now. 23 sites: system.py's maintenance and health queries get DbMaintenance and SystemHealth owners; job queries land on DBWorker (table-allowlist guarded); counts move to their cache owners. The artwork-matches reset now reports the DELETE's own rowcount — the old pre-count claimed user-locked rows as deleted while preserving them. datetime.utcnow() leaves the repo (4 sites, now(timezone.utc); cutoff comparisons proven byte-equivalent against both stored shapes). VACUUM and ping get honest owners; every ORDER BY under LIMIT carries an id tiebreaker.
|
Warning Review limit reachedYou’ve reached a temporary PR review limit under our Fair Usage Limits Policy. Next review available in: 38 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the 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 configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (17)
Comment |
…faces-system # Conflicts: # backend/util/database/media_stats.py
Stacked on #531 (the media_cache domain split) — this diff shows both until #531 merges, then collapses to G1c alone.
What
backend/apiholds zero raw SQL after this. 23 sites moved: system.py's maintenance and health queries getDbMaintenanceandSystemHealthowners; job queries land onDBWorker(table-allowlist guarded); counts move to their cache owners; the stray rawsqlite3.connectVACUUM gets an honest owner./api/system/db/artwork-matches/resetcounted user-locked rows (ignored=1 / user_confirmed=1) as deleted while preserving them — the pre-count's WHERE didn't match the DELETE's. The response now reports the DELETE's own rowcount, covered at both layers.datetime.utcnow()leaves the repo (4 sites →datetime.now(timezone.utc)): the two cutoff comparisons are proven byte-equivalent by brute force against both stored timestamp shapes (0 mismatches across 1080×16 cases); the value sites render identically (verified through the frontend's date path).Verification
32 new tests, every one mutation-proven to redden (one test was dropped for being unable to discriminate — SQLite's index reverse-scan already returns the tied order — documented in-code); full suite green ×2 (1590 tests); ruff clean.
Flagged for later (ledgered)
media_cache.created_at cutoff separator mismatch (real pre-existing bug — same-day rows silently excluded from media_added); scheduler.py's two raw snapshot writes → SystemHealth owners; the db.worker lambda property; the cancel-endpoint TOCTOU wording.