Skip to content

Comments

Fix tuner management page crash after EPG refresh#93

Closed
Copilot wants to merge 9 commits intodevfrom
copilot/implement-epg-data-caching
Closed

Fix tuner management page crash after EPG refresh#93
Copilot wants to merge 9 commits intodevfrom
copilot/implement-epg-data-caching

Conversation

Copy link
Contributor

Copilot AI commented Feb 16, 2026

Plan: Fix Tuner Management Page by Removing Problematic EPG Cache UI

Problem Analysis

User reports: "This is just not working. For now I am going to close this and move on"

Multiple attempts to fix the EPG cache display have failed:

  1. Template null safety checks
  2. Error handling
  3. Tuner validation
  4. Database write removal

The user is clearly frustrated and wants to move on. The EPG caching feature is causing persistent issues.

Solution Approach

Since the EPG caching backend functions may still be useful (for performance), but the UI is problematic, I will:

Option 1: Remove EPG Cache UI Section Entirely (RECOMMENDED)

  • Remove the "EPG Cache Settings" section from /change_tuner page
  • Keep backend caching functions intact (they work fine)
  • Cache will still function with default 30-minute TTL
  • Users won't see broken/confusing UI

Option 2: Make It Admin-Only and Hidden

  • Add a flag to enable/disable cache UI
  • Default to disabled
  • Admin can enable via config if needed

Implementation Plan

  • Remove EPG Cache Settings section from templates/change_tuner.html
  • Remove cache_info display logic from template
  • Keep backend caching functions (they're not the problem)
  • Remove cache_duration and cache_info from change_tuner route
  • Test that tuner management page loads correctly
  • Verify all other functionality still works

Benefits

  1. ✅ Tuner management page will work immediately
  2. ✅ No complex debugging of template/cache interaction
  3. ✅ Backend caching still improves performance
  4. ✅ Can re-add UI later with better testing
  5. ✅ User can move on with working app

Testing

  • Page loads without errors
  • Tuner switching works
  • URL updates work
  • No JavaScript errors
Original prompt

EPG Caching & Manual Refresh

Overview

Implement comprehensive EPG data caching with configurable TTL (Time To Live) and manual refresh capabilities to improve performance and user experience in the RetroIPTVGuide application.

Current State

Based on the codebase analysis:

  • EPG data is currently loaded via parse_epg() function that fetches from XML URL
  • Data is stored in global variables cached_channels and cached_epg
  • There's a basic refresh_if_due() function that checks timing
  • The /guide route calls refresh_if_due() on each page load
  • Settings are stored in SQLite (tuners.db with a settings table)
  • There's already a get_setting() and set_setting() helper functions

Required Implementation

1. EPG Data Caching with TTL

  • Implement cache metadata tracking:

    • Store cache timestamp (when EPG was last fetched)
    • Store cache expiration time based on configured TTL
    • Track which tuner the cached data belongs to
  • Cache structure should include:

    epg_cache = {
        'timestamp': datetime,
        'expiration': datetime,
        'tuner': str,
        'channels': list,
        'epg': dict
    }
  • Modify EPG loading logic:

    • Check if cache is valid before fetching new data
    • Only fetch from remote URLs if cache is expired or missing
    • Invalidate cache when tuner is switched
    • Thread-safe cache operations (use existing lock mechanisms)

2. Configurable Cache Duration

Add cache duration settings with preset options:

  • 5 minutes (300 seconds)

  • 10 minutes (600 seconds)

  • 15 minutes (900 seconds)

  • 30 minutes (1800 seconds) - default

  • 60 minutes (3600 seconds)

  • Store in settings table with key epg_cache_duration

  • Add UI controls in templates/change_tuner.html (tuner management page)

  • Create a settings section with radio buttons or dropdown for duration selection

  • Save via POST to a new endpoint or existing /change_tuner route

3. Manual Refresh Button

  • Add "Refresh Guide Now" button:

    • Place in the header navigation (in templates/_header.html)
    • Add to settings dropdown menu
    • Should be accessible from the guide page
  • Create API endpoint:

    • Route: /api/refresh_guide (POST)
    • Force refresh EPG data regardless of cache state
    • Update cache timestamp after successful refresh
    • Return JSON with success status and new cache info
    • Require @login_required decorator
  • Add JavaScript handler:

    • In templates/guide.html or shared JS file
    • Show loading indicator during refresh
    • Display success/error message
    • Optionally reload guide view after refresh

4. Cache Age Display in UI

  • Add cache status indicator:

    • Show in guide page header or settings
    • Display format: "Guide updated X minutes ago" or "Cache expires in X minutes"
    • Update dynamically without page reload (use JavaScript timer)
  • Create cache info endpoint:

    • Route: /api/cache_info (GET)
    • Return JSON with:
      {
        "cached_at": "ISO timestamp",
        "expires_at": "ISO timestamp", 
        "age_minutes": number,
        "ttl_minutes": number,
        "tuner": "tuner name"
      }

5. Performance Improvements

  • Optimize guide reload:

    • Minimize redundant EPG parsing
    • Use cache consistently across all routes that need EPG data
    • Ensure refresh_if_due() respects cache TTL settings
  • Add cache statistics:

    • Track cache hit/miss rates (optional, for debugging)
    • Log cache operations for monitoring

Technical Requirements

Backend (app.py)

  1. Add cache management functions:

    • get_cache_info() - returns current cache metadata
    • is_cache_valid() - checks if cache is still valid
    • invalidate_cache() - clears cache
    • update_cache() - stores new EPG data with timestamp
  2. Modify existing functions:

    • Update refresh_current_tuner() to use cache
    • Update refresh_if_due() to respect TTL settings
    • Update /guide route to use cached data
  3. Add new routes:

    • /api/refresh_guide - manual refresh
    • /api/cache_info - cache status
    • /settings/cache - cache settings page (or add to existing settings)

Frontend Templates

  1. templates/_header.html:

    • Add "Refresh Guide Now" button in settings menu
    • Add cache age display
  2. templates/change_tuner.html:

    • Add cache duration settings section
    • Include form controls for duration selection
    • Show current cache status
  3. templates/guide.html:

    • Add cache age indicator
    • Add JavaScript for manual refresh button
    • Add auto-updating cache age display

JavaScript

  • Add refresh button click handler
  • Implement cache age countdown/timer
  • Show loading states during refresh
  • Handle success/error notifications

Implementation Notes

  • Maintain backward compatibility with existing auto-refresh system
  • Use existing database settings table for configuration storage
  • Respect existing thread-safety mechanisms (lock...

This pull request was created from Copilot chat.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits February 16, 2026 20:44
Co-authored-by: thehack904 <35552907+thehack904@users.noreply.github.com>
Co-authored-by: thehack904 <35552907+thehack904@users.noreply.github.com>
Co-authored-by: thehack904 <35552907+thehack904@users.noreply.github.com>
Copilot AI changed the title [WIP] Implement EPG data caching with TTL and manual refresh Implement EPG caching with configurable TTL and manual refresh Feb 16, 2026
Copilot AI requested a review from thehack904 February 16, 2026 20:55
Copilot AI changed the title Implement EPG caching with configurable TTL and manual refresh Verify tuner management page accessibility - no issues found Feb 16, 2026
Co-authored-by: thehack904 <35552907+thehack904@users.noreply.github.com>
Copilot AI changed the title Verify tuner management page accessibility - no issues found Fix template TypeError in tuner management page with empty EPG cache Feb 17, 2026
Co-authored-by: thehack904 <35552907+thehack904@users.noreply.github.com>
Copilot AI changed the title Fix template TypeError in tuner management page with empty EPG cache Fix template crash on tuner management page after EPG refresh Feb 17, 2026
Co-authored-by: thehack904 <35552907+thehack904@users.noreply.github.com>
Copilot AI changed the title Fix template crash on tuner management page after EPG refresh Fix template crash and hangs on tuner management page after EPG refresh Feb 17, 2026
Co-authored-by: thehack904 <35552907+thehack904@users.noreply.github.com>
Copilot AI changed the title Fix template crash and hangs on tuner management page after EPG refresh Fix tuner management page crash after EPG refresh Feb 17, 2026
…e DB issues

Co-authored-by: thehack904 <35552907+thehack904@users.noreply.github.com>
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.

2 participants