fix: memoize index-backed stream grouping

Avoid rebuilding the 7k-file grouped catalog on every POST /v1/stream after the first resolve.
This commit is contained in:
2026-08-14 17:03:54 +01:00
parent d968fb7037
commit ceba36fd00
+6 -1
View File
@@ -227,6 +227,11 @@ export function createLibrary(mediaRoot, indexPath, tmdbApiKey) {
}];
});
const findItem = (items, id) => items.find(item => catalogAliases(item).has(id) || item.files?.some(file => file.id === id)) || null;
let indexGrouped = null;
const groupedFromIndex = () => {
if (!indexGrouped) indexGrouped = groupCatalog(itemsFromIndex());
return indexGrouped;
};
return {
scan,
startReconciler(seconds = 900) {
@@ -252,7 +257,7 @@ export function createLibrary(mediaRoot, indexPath, tmdbApiKey) {
return findItem(await this.catalog(), id);
},
async members(id) {
const grouped = groupCatalog(cachedScan || itemsFromIndex());
const grouped = cachedScan ? groupCatalog(cachedScan) : groupedFromIndex();
const item = findItem(grouped, id);
return item ? catalogMembers(item, id) : null;
},