videos: silence the automatic channel refresh before downloads (#671)

The channel downloader refreshes a Channel's files before downloading,
already passing send_events=False, but the parameter was never plumbed
into the file worker, so every pre-download refresh notified the user.
FileTask now carries send_events and handle_refresh skips the
Refreshing/Refreshed events when it is False. User-requested refreshes
and global refreshes still send Events.

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
lrnselfreliance 2026-08-20 15:15:08 -06:00 • committed by Roland
parent 9278103554
commit 42595400b4
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
3 changed files with 64 additions and 16 deletions

View file

@ -1019,7 +1019,7 @@ class Channel(ModelHelper, Base):
external_paths = cls._get_external_file_paths(session, id_, directory)
# Queue refresh immediately so caller can await the job.
job_id = file_worker.queue_refresh([directory] + external_paths)
job_id = file_worker.queue_refresh([directory] + external_paths, send_events=send_events)
# Background task handles post-processing after job completes.
async def _():

View file

@ -0,0 +1,39 @@
"""Tests that Channel.refresh_files() only sends Events when requested.
The Channel downloader refreshes a Channel before downloading; that refresh should not
notify the user (send_events=False), while a user-requested refresh should.
"""
import pytest
from modules.videos.models import Channel
from wrolpi.common import await_background_tasks
from wrolpi.conftest import await_file_worker
@pytest.mark.asyncio
async def test_channel_refresh_files_send_events_false(
async_client, test_session, channel_factory, video_file_factory, events_fixture):
"""Channel.refresh_files(send_events=False) must not send refresh Events."""
channel = channel_factory(name='MyChannel')
video_file_factory(channel.directory / 'video.mp4')
Channel.refresh_files(channel.id, send_events=False)
await await_file_worker()
await await_background_tasks()
events_fixture.assert_no_event('directory_refresh')
events_fixture.assert_no_event('files_refreshed')
@pytest.mark.asyncio
async def test_channel_refresh_files_send_events_default(
async_client, test_session, channel_factory, video_file_factory, events_fixture):
"""Channel.refresh_files() sends refresh Events by default."""
channel = channel_factory(name='MyChannel')
video_file_factory(channel.directory / 'video.mp4')
Channel.refresh_files(channel.id)
await await_file_worker()
await await_background_tasks()
events_fixture.assert_has_event('directory_refresh')