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 <noreply@anthropic.com>

* 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 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
lrnselfreliance 2026-12-01 14:22:36 -07:00 • committed by GitHub
parent 570c63ffc7
commit d8eba53c24
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 65 additions and 5 deletions

View file

@ -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);

View file

@ -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(<VideoPage videoFile={videoFile({id: 5, name: 'Some Channel'})} fetchVideo={() => 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(<VideoPage videoFile={videoFile(null)} fetchVideo={() => 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();
});
});