fix(live): keep channel search responsive (#25)

Filter projected live channels locally in the browser and apply server-side search and language filters before costly enrichment work.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
blomios
2026-10-06 13:08:16 +02:00
parent 5baf8d5a33
commit 45d1fe29d3
7 changed files with 210 additions and 48 deletions

View File

@ -3,6 +3,7 @@ const assert = require('node:assert/strict');
const Database = require('better-sqlite3');
const {
normalizeChannelName,
getChannelPage,
projectCatalog,
markProjectionBuilding,
projectionState,
@ -55,6 +56,13 @@ function createProjectionDb() {
is_favorite INTEGER DEFAULT 0,
data JSON
);
CREATE TABLE favorites (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER NOT NULL,
source_id INTEGER NOT NULL,
item_id TEXT NOT NULL,
item_type TEXT NOT NULL
);
`);
const { ensureColumns } = require('../server/db/liveProjectionSchema');
ensureColumns(db, 'playlist_items', LIVE_PROJECTION_COLUMNS);
@ -260,3 +268,24 @@ test('API serialization preserves an M3U groupTitle over the stored category fal
assert.equal(channel.groupTitle, 'M3U Sports France');
assert.equal(channel.variants[0].categoryName, 'M3U Sports France');
});
test('search and language filters run before expensive standard and EPG enrichment', () => {
const db = createProjectionDb();
seedProjectionChannel(db, 'bein-fr', '|FR| beIN Sports 1 HD');
seedProjectionChannel(db, 'bein-en', '|UK| beIN Sports 1 4K');
seedProjectionChannel(db, 'euro-fr', '|FR| Eurosport HD');
require('../server/services/liveProjectionService').rebuild(db);
let standardCalls = 0;
let epgCalls = 0;
const page = getChannelPage({ q: 'Bein Sport 1', languages: ['fr'], epgSources: [] }, db, {
iptvOrgCatalog: { findMatch: () => { standardCalls += 1; return null; } },
epgMatching: { findBestMatch: () => { epgCalls += 1; return null; } }
});
assert.equal(page.channels.length, 1);
assert.equal(page.channels[0].language.code, 'fr');
assert.deepEqual(page.availableLanguages.map(language => language.code).sort(), ['en', 'fr']);
assert.equal(standardCalls, 1);
assert.equal(epgCalls, 1);
});

107
test/t25Frontend.test.js Normal file
View File

@ -0,0 +1,107 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const { JSDOM } = require('jsdom');
const root = path.resolve(__dirname, '..');
const script = relativePath => fs.readFileSync(path.join(root, 'public', relativePath), 'utf8');
const wait = milliseconds => new Promise(resolve => setTimeout(resolve, milliseconds));
function createChannelList() {
const dom = new JSDOM(`<!doctype html>
<input id="channel-search">
<select id="source-select"><option value="">All Sources</option></select>
<input id="show-hidden" type="checkbox">
<button id="toggle-groups"></button>
<div id="channel-language-filter"></div>
<div id="channel-list-status"></div>
<div id="context-menu"></div>
<div id="channel-list"></div>
`, { url: 'http://nodecast.test/', runScripts: 'outside-only', pretendToBeVisual: true });
const { window } = dom;
window.IntersectionObserver = class { observe() {} disconnect() {} };
window.eval(script('js/icons.js'));
window.eval(script('js/services/channelLanguageDetection.js'));
window.eval(script('js/services/channelLanguageFusion.js'));
window.eval(script('js/services/channelVariantGrouping.js'));
window.eval(script('js/services/liveChannelProjection.js'));
window.eval(`${script('js/components/ChannelList.js')}\nwindow.ChannelList = ChannelList;`);
window.app = {
player: { settings: { liveChannelListMode: 'flat', languageDetectionMode: 'algo' } },
epgGuide: { getCurrentProgram: () => null, loadError: null }
};
return { dom, window, channelList: new window.ChannelList() };
}
function projectedResponse() {
const channel = (id, name, language) => ({
id: `${id}:${language}`, logicalChannelId: id, displayName: name,
language: { code: language, short: language.toUpperCase(), label: language === 'fr' ? 'French' : 'English', confidence: 95 },
selectedVariantId: `1:${id}-${language}`,
variants: [{ id: `${id}-${language}`, sourceId: 1, name: `${name} ${language.toUpperCase()}`, categoryName: 'Sports', isHidden: false }]
});
return {
projection: { stale: false },
filters: { availableLanguages: [
{ code: 'en', short: 'EN', label: 'English' },
{ code: 'fr', short: 'FR', label: 'French' }
] },
channels: [
channel('bein-1', 'beIN Sports 1', 'fr'),
channel('bein-1', 'beIN Sports 1', 'en'),
channel('news', 'World News', 'en')
]
};
}
test('typing filters a loaded projection locally with flexible matching and no API request', async () => {
const { dom, window, channelList } = createChannelList();
let calls = 0;
window.API = { live: { getChannels: async options => {
calls++;
assert.equal(options.q, '');
assert.deepEqual([...options.languages], []);
return projectedResponse();
} } };
await channelList.loadProjectedChannels();
channelList.render();
calls = 0;
channelList.searchInput.value = 'Bein Sport 1';
channelList.searchInput.dispatchEvent(new window.Event('input', { bubbles: true }));
await wait(100);
assert.equal(calls, 0);
assert.equal(channelList.filteredChannels.length, 2);
assert.ok(channelList.filteredChannels.every(channel => channel.displayName === 'beIN Sports 1'));
assert.equal(channelList.listStatus.textContent, '2 channel entries shown');
dom.window.close();
});
test('language selection filters the complete loaded catalog immediately without API', async () => {
const { dom, window, channelList } = createChannelList();
let calls = 0;
window.API = { live: { getChannels: async () => { calls++; return projectedResponse(); } } };
await channelList.loadProjectedChannels();
channelList.render();
calls = 0;
channelList.setLanguageSelection('fr');
assert.equal(calls, 0);
assert.equal(channelList.filteredChannels.length, 1);
assert.equal(channelList.filteredChannels[0].language.code, 'fr');
dom.window.close();
});
test('Escape clears channel search while preserving language-panel Escape behavior', async () => {
const { dom, window, channelList } = createChannelList();
window.API = { live: { getChannels: async () => projectedResponse() } };
await channelList.loadProjectedChannels();
channelList.searchInput.value = 'news';
window.document.dispatchEvent(new window.KeyboardEvent('keydown', { key: 'Escape', bubbles: true }));
assert.equal(channelList.searchInput.value, '');
assert.equal(channelList.filteredChannels.length, 3);
dom.window.close();
});