Popularity computation background job #114

Open
opened 2026-07-13 17:52:28 +00:00 by Ai_Agent · 0 comments
Collaborator

Add a scheduled background job that aggregates view log data into popularity scores for each timeframe (Daily, Weekly, Monthly, AllTime).

Job: ComputePopularityJob

Extends the existing Job abstract class (like FileSystemCrawlJob, ThumbnailJob, etc.).

Algorithm

For each entity type (Asset, Album, Person) and each timeframe:

  1. Daily: Views in the last 24 hours
  2. Weekly: Views in the last 7 days
  3. Monthly: Views in the last 30 days
  4. AllTime: Total views ever (or within a configurable cutoff, e.g., last 365 days)

For each (entity, timeframe) pair:

  • Count distinct (ViewerIp, ViewerUserId) tuples per entity within the window
  • Sort by count descending
  • Take top-N (configurable, default 50)

Caching

Write results to an in-memory cache (IMemoryCache or ConcurrentDictionary) for fast API reads. Optionally back it with a PopularityCache DB table for persistence across restarts.

Scheduling

  • Register in JobScheduler to run nightly (e.g., Timer(TimeSpan.FromHours(24)))
  • Also triggerable on-demand from /api/jobs (admin) via existing job infrastructure

Edge cases

  • Entities with zero views in a timeframe are excluded
  • Deleted/soft-deleted entities excluded from results
  • New entities with no views yet: not popular (correct)
  • If view logs are empty, return empty arrays (no crash)

Settings integration

Read thresholds from settings (see #117):

  • PopularMinViews — minimum views to qualify
  • PopularMaxResults — top-N limit per timeframe

Part of: #110

Add a scheduled background job that aggregates view log data into popularity scores for each timeframe (Daily, Weekly, Monthly, AllTime). ### Job: `ComputePopularityJob` Extends the existing `Job` abstract class (like `FileSystemCrawlJob`, `ThumbnailJob`, etc.). ### Algorithm For each entity type (Asset, Album, Person) and each timeframe: 1. **Daily**: Views in the last 24 hours 2. **Weekly**: Views in the last 7 days 3. **Monthly**: Views in the last 30 days 4. **AllTime**: Total views ever (or within a configurable cutoff, e.g., last 365 days) For each (entity, timeframe) pair: - Count distinct `(ViewerIp, ViewerUserId)` tuples per entity within the window - Sort by count descending - Take top-N (configurable, default 50) ### Caching Write results to an in-memory cache (`IMemoryCache` or `ConcurrentDictionary`) for fast API reads. Optionally back it with a `PopularityCache` DB table for persistence across restarts. ### Scheduling - Register in `JobScheduler` to run nightly (e.g., `Timer(TimeSpan.FromHours(24))`) - Also triggerable on-demand from `/api/jobs` (admin) via existing job infrastructure ### Edge cases - Entities with zero views in a timeframe are excluded - Deleted/soft-deleted entities excluded from results - New entities with no views yet: not popular (correct) - If view logs are empty, return empty arrays (no crash) ### Settings integration Read thresholds from settings (see #117): - `PopularMinViews` — minimum views to qualify - `PopularMaxResults` — top-N limit per timeframe --- Part of: #110
Ai_Agent added the enhancementarea:backend labels 2026-07-13 17:52:28 +00:00
Ai_Agent added the Need Triage label 2026-07-14 13:07:51 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: MilkyShots/MilkyShots#114