Skip to content

Comments

feat(search): Implement 'never_broadcasted' filter for media search and add i…#206

Open
sreeshanth-soma wants to merge 1 commit intoopenbroadcaster:5.5-developfrom
sreeshanth-soma:search-media-never-broadcasted
Open

feat(search): Implement 'never_broadcasted' filter for media search and add i…#206
sreeshanth-soma wants to merge 1 commit intoopenbroadcaster:5.5-developfrom
sreeshanth-soma:search-media-never-broadcasted

Conversation

@sreeshanth-soma
Copy link
Member

Closes: #185

Summary

Adds a new "Never Been Broadcast" boolean filter to Advanced Search, allowing users to find media that has never been played by any player. Designed to help narrow down material hidden in the archive and to support dynamic sections for unplayed content.

Problem

In large databases (e.g., CJUC with 166K+ media items), an estimated 20–30% of media has never been played. There was no way to search for or identify this unplayed content.

Changes

Backend — core/models/media_model.php

  • Added 'never_broadcasted' to $allowed_filters in search_filters_validate()
  • Added special handling in search_filters_where_array() that bypasses normal column mapping and uses a correlated subquery:
    • Yes (value=1): NOT EXISTS (SELECT 1 FROM players_log WHERE players_log.media_id = media.id)
    • No (value=0): EXISTS (SELECT 1 FROM players_log WHERE players_log.media_id = media.id)

Frontend — public/html/sidebar/advanced_search.html

  • Added <option value="never_broadcasted" ...>Never Been Broadcast</option> as a boolean filter (Yes/No)

Performance

Uses NOT EXISTS with a correlated subquery — the most efficient SQL pattern for this use case:

  • Short-circuits on the first matching row (doesn't scan entire players_log)
  • No duplicates (unlike LEFT JOIN which multiplies rows for media broadcast multiple times)
  • No aggregation (unlike COUNT(*) / HAVING approaches)
  • players_log.media_id is already indexed (MUL key), so lookups are O(log n)
  • Search results are paginated via LIMIT/OFFSET, so only one page is returned at a time

Expected query time at 170K items: sub-second (~50–200ms with index).

Verification

  • Created a test player and inserted a players_log entry for one media item to simulate a broadcast
  • "Never Been Broadcast" = Yes → returned 3 results (media without any broadcast log)
  • "Never Been Broadcast" = No → returned remaining media that has been broadcast
  • Existing filters (Artist, Status, etc.) continue to work correctly
image image

@sreeshanth-soma sreeshanth-soma changed the title feat: Implement 'never_broadcasted' filter for media search and add i… feat(search): Implement 'never_broadcasted' filter for media search and add i… Feb 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant