From d8eba53c247fb87f402e7ab6f6481f145f49ea88 Mon Sep 17 00:00:00 2001 From: lrnselfreliance <33263708+lrnselfreliance@users.noreply.github.com> Date: Tue, 1 Dec 2026 14:22:36 -0700 Subject: [PATCH] Video page: show the Channel from the video response (#1060) * Video page: show the Channel from the video response The video page fetched the whole Channel just to show its name, and that endpoint computes the Channel's statistics, which took seconds on a large Channel from a cold disk cache. The video response already carries the Channel's id and name. The URL's channel id is still fetched when the Video has no Channel, and an unfetched Channel no longer renders an empty link. Co-Authored-By: Claude Opus 5.5 * Video page: drop the unreachable URL channel fallback VideoPage is only routed at videos/:fileGroupId, so the URL never carries a channel id. Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Opus 5.5 --- app/src/components/VideoPlayer.js | 10 ++-- app/src/components/VideoPlayerChannel.test.js | 60 +++++++++++++++++++ 2 files changed, 65 insertions(+), 5 deletions(-) create mode 100644 app/src/components/VideoPlayerChannel.test.js diff --git a/app/src/components/VideoPlayer.js b/app/src/components/VideoPlayer.js index 1903ccd9..e75642cf 100644 --- a/app/src/components/VideoPlayer.js +++ b/app/src/components/VideoPlayer.js @@ -1,7 +1,7 @@ import React, {useEffect, useState} from 'react'; import {useHotkeys} from 'react-hotkeys-hook'; import {deleteFileGroups, downloadVideoMetadata, tagFileGroup, untagFileGroup} from "../api"; -import {Link, useNavigate, useParams} from "react-router"; +import {Link, useNavigate} from "react-router"; import _ from "lodash"; import { APIButton, @@ -19,7 +19,7 @@ import { useTitle } from "./Common"; import {VideoPlaceholder} from "./Placeholder"; -import {useChannel, useOneQuery, useVideoCaptions, useVideoExtras} from "../hooks/customHooks"; +import {useOneQuery, useVideoCaptions, useVideoExtras} from "../hooks/customHooks"; import {useMediaProgress} from "../hooks/useFileProgress"; import {Button, Grid, Header, Icon, Label, Loading, Panel, Placeholder, Tabs, TextInput} from "./ui"; import {VideoCard} from "./Videos"; @@ -242,9 +242,9 @@ function VideoPage({videoFile, prevFile, nextFile, fetchVideo, ...props}) { videoRef.current.currentTime = seconds; } - // Get the Video's channel, fallback to the URL's channel id. - const {channelId} = useParams(); - const {channel} = useChannel(video && video.channel_id ? video.channel_id : channelId); + // The video response carries its Channel's id and name. Never fetch the whole Channel here, it computes + // the Channel's statistics, which is slow on a large Channel. + const channel = video?.channel || null; const {comments, description: videoDescription, fetchDescription} = useVideoExtras(videoFile?.id); const {captions, captionsLoading, fetchCaptions} = useVideoCaptions(videoFile?.id); diff --git a/app/src/components/VideoPlayerChannel.test.js b/app/src/components/VideoPlayerChannel.test.js new file mode 100644 index 00000000..6fa6d4e5 --- /dev/null +++ b/app/src/components/VideoPlayerChannel.test.js @@ -0,0 +1,60 @@ +import React from 'react'; +import {render, screen, waitFor} from '../test-utils'; +import VideoPage from './VideoPlayer'; +import {getChannel} from '../api'; + +// The video response carries the Video's Channel (id and name); fetching the whole Channel only to +// show its name costs a statistics query that takes seconds on a large, cold Channel. + +jest.mock('../api', () => { + const actual = jest.requireActual('../api'); + return { + ...actual, + getChannel: jest.fn(), + getVideoComments: jest.fn().mockResolvedValue([]), + getVideoDescription: jest.fn().mockResolvedValue(''), + getVideoCaptions: jest.fn().mockResolvedValue([]), + }; +}); + +const videoFile = (channel) => ({ + id: 3, + name: 'video.mp4', + title: 'A Video', + primary_path: 'channel/video.mp4', + files: [{path: 'channel/video.mp4', mimetype: 'video/mp4'}], + tags: [], + video: { + id: 3, + channel, + channel_id: channel ? channel.id : null, + video_path: 'channel/video.mp4', + caption_files: [], + codec_names: [], + codec_types: [], + }, +}); + +describe('VideoPage channel', () => { + beforeEach(() => getChannel.mockReset()); + + test("shows the Video's Channel without fetching the Channel", async () => { + render( null}/>); + + const link = await screen.findByRole('link', {name: 'Some Channel'}); + expect(link).toHaveAttribute('href', '/videos/channel/5/video'); + // Let any effects that would fetch settle. + await waitFor(() => expect(screen.getByText('A Video')).toBeInTheDocument()); + expect(getChannel).not.toHaveBeenCalled(); + }); + + test('a Video without a Channel shows no Channel link', async () => { + render( null}/>); + + await waitFor(() => expect(screen.getByText('A Video')).toBeInTheDocument()); + const channelLinks = screen.queryAllByRole('link') + .filter(i => (i.getAttribute('href') || '').startsWith('/videos/channel/')); + expect(channelLinks).toHaveLength(0); + expect(getChannel).not.toHaveBeenCalled(); + }); +});