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