Use bulk watched-status loading in client
@@ -1708,6 +1708,7 @@ function isSidebarLoadStale (item, sidebarLoadId)
1708
1708
*/
1709
1709
function renderSidebarDuplicates (item, duplicates)
1710
1710
{
1711
if (typeof document === 'undefined' || typeof document.getElementById !== 'function') return;
1711
1712
const panel = document.getElementById('sidebar-duplicates');
1712
1713
if (!panel) return;
1713
1714
@@ -4247,26 +4248,51 @@ async function loadWatchedStatusesForCurrentDir ()
4247
4248
4248
4249
const loadId = ++STATE.watchedLoadId;
4249
4250
4250
const statuses = await Promise.all(videoItems.map(async (item) =>
4251
let statusMap = null;
4252
const filePaths = videoItems.map((item) => item.path);
4253
4254
const bulk = await api('POST', '/files/watched-statuses', { filePaths }).catch(() => null);
4255
if (bulk && bulk.statuses && typeof bulk.statuses === 'object')
4251
4256
{
4252
const meta = await api('GET', `/files/meta?file=${encodeURIComponent(item.path)}`).catch(() => null);
4253
return {
4254
path: item.path,
4255
status: watchStatusFromWatchedBy(meta && meta.watchedBy),
4256
};
4257
}));
4257
statusMap = {};
4258
for (const item of videoItems)
4259
{
4260
const status = String(bulk.statuses[item.path] || '').toLowerCase();
4261
statusMap[item.path] = status === 'fully' || status === 'partway' ? status : null;
4262
}
4263
}
4264
4265
// Compatibility fallback for older servers that do not expose bulk statuses yet.
4266
if (!statusMap)
4267
{
4268
statusMap = {};
4269
const statuses = await Promise.all(videoItems.map(async (item) =>
4270
{
4271
const meta = await api('GET', `/files/meta?file=${encodeURIComponent(item.path)}`).catch(() => null);
4272
return {
4273
path: item.path,
4274
status: watchStatusFromWatchedBy(meta && meta.watchedBy),
4275
};
4276
}));
4277
4278
for (const entry of statuses)
4279
{
4280
statusMap[entry.path] = entry.status;
4281
}
4282
}
4258
4283
4259
4284
if (loadId !== STATE.watchedLoadId) return;
4260
4285
if (!samePath(STATE.currentDir, dirAtStart)) return;
4261
4286
if (typeof document === 'undefined' || typeof document.querySelectorAll !== 'function') return;
4262
4287
4263
for (const entry of statuses)
4288
for (const item of videoItems)
4264
4289
{
4265
if (entry.status) STATE.watchedStatusByPath[entry.path] = entry.status;
4266
else delete STATE.watchedStatusByPath[entry.path];
4290
const status = statusMap[item.path] || null;
4291
if (status) STATE.watchedStatusByPath[item.path] = status;
4292
else delete STATE.watchedStatusByPath[item.path];
4267
4293
4268
const iconEl = findTileIconByPath(entry.path);
4269
renderWatchedOverlayOnIcon(iconEl, entry.status);
4294
const iconEl = findTileIconByPath(item.path);
4295
renderWatchedOverlayOnIcon(iconEl, status);
4270
4296
}
4271
4297
}
4272
4298
@@ -1708,6 +1708,7 @@ function isSidebarLoadStale (item, sidebarLoadId)1708
*/1708
*/1709
function renderSidebarDuplicates (item, duplicates)1709
function renderSidebarDuplicates (item, duplicates)1710
{1710
{1711
if (typeof document === 'undefined' || typeof document.getElementById !== 'function') return;1711
const panel = document.getElementById('sidebar-duplicates');1712
const panel = document.getElementById('sidebar-duplicates');1712
if (!panel) return;1713
if (!panel) return;1713
1714
@@ -4247,26 +4248,51 @@ async function loadWatchedStatusesForCurrentDir ()4247
4248
4248
const loadId = ++STATE.watchedLoadId;4249
const loadId = ++STATE.watchedLoadId;4249
4250
4250
const statuses = await Promise.all(videoItems.map(async (item) =>4251
let statusMap = null;4252
const filePaths = videoItems.map((item) => item.path);4253
4254
const bulk = await api('POST', '/files/watched-statuses', { filePaths }).catch(() => null);4255
if (bulk && bulk.statuses && typeof bulk.statuses === 'object')4251
{4256
{4252
const meta = await api('GET', `/files/meta?file=${encodeURIComponent(item.path)}`).catch(() => null);4257
statusMap = {};4253
return {4258
for (const item of videoItems)4254
path: item.path,4259
{4255
status: watchStatusFromWatchedBy(meta && meta.watchedBy),4260
const status = String(bulk.statuses[item.path] || '').toLowerCase();4256
};4261
statusMap[item.path] = status === 'fully' || status === 'partway' ? status : null;4257
}));4262
}4263
}4264
4265
// Compatibility fallback for older servers that do not expose bulk statuses yet.4266
if (!statusMap)4267
{4268
statusMap = {};4269
const statuses = await Promise.all(videoItems.map(async (item) =>4270
{4271
const meta = await api('GET', `/files/meta?file=${encodeURIComponent(item.path)}`).catch(() => null);4272
return {4273
path: item.path,4274
status: watchStatusFromWatchedBy(meta && meta.watchedBy),4275
};4276
}));4277
4278
for (const entry of statuses)4279
{4280
statusMap[entry.path] = entry.status;4281
}4282
}4258
4283
4259
if (loadId !== STATE.watchedLoadId) return;4284
if (loadId !== STATE.watchedLoadId) return;4260
if (!samePath(STATE.currentDir, dirAtStart)) return;4285
if (!samePath(STATE.currentDir, dirAtStart)) return;4261
if (typeof document === 'undefined' || typeof document.querySelectorAll !== 'function') return;4286
if (typeof document === 'undefined' || typeof document.querySelectorAll !== 'function') return;4262
4287
4263
for (const entry of statuses)4288
for (const item of videoItems)4264
{4289
{4265
if (entry.status) STATE.watchedStatusByPath[entry.path] = entry.status;4290
const status = statusMap[item.path] || null;4266
else delete STATE.watchedStatusByPath[entry.path];4291
if (status) STATE.watchedStatusByPath[item.path] = status;4292
else delete STATE.watchedStatusByPath[item.path];4267
4293
4268
const iconEl = findTileIconByPath(entry.path);4294
const iconEl = findTileIconByPath(item.path);4269
renderWatchedOverlayOnIcon(iconEl, entry.status);4295
renderWatchedOverlayOnIcon(iconEl, status);4270
}4296
}4271
}4297
}4272
4298
@@ -159,6 +159,23 @@ describe('page load smoke test', () =>
159
159
{
160
160
res.json({ ok: true, updated: true });
161
161
});
162
app.post('/api/files/watched-statuses', (req, res) =>
163
{
164
const requested = Array.isArray(req.body?.filePaths) ? req.body.filePaths : [];
165
const statuses = {};
166
167
for (const rawPath of requested)
168
{
169
const filePath = String(rawPath || '');
170
const allItems = Object.values(listFixture).flat();
171
const item = allItems.find((it) => it.path === filePath);
172
const watchedBy = metaWatchedByFixture[filePath] || (item && item.watchedBy) || {};
173
const status = String(watchedBy.tester || '').toLowerCase();
174
if (status === 'fully' || status === 'partway') statuses[filePath] = status;
175
}
176
177
res.json({ statuses });
178
});
162
179
app.get('/api/files/root-access', (req, res) =>
163
180
{
164
181
const rootPath = String(req.query.rootPath || '');
@@ -768,15 +785,10 @@ describe('page load smoke test', () =>
768
785
};
769
786
metaWatchedByFixture['/data/watched-full.mkv'] = { tester: 'fully' };
770
787
metaWatchedByFixture['/data/watched-part.mkv'] = { tester: 'partway' };
771
metaDelayMsFixture['/data/watched-full.mkv'] = 80;
772
metaDelayMsFixture['/data/watched-part.mkv'] = 80;
773
788
774
789
const { dom, runtimeErrors } = await bootClient();
775
790
expect(runtimeErrors).toEqual([]);
776
791
777
await waitFor(dom, () => !!dom.window.document.querySelector('.file-item[data-path="/data/watched-full.mkv"]'));
778
expect(dom.window.document.querySelector('.file-item[data-path="/data/watched-full.mkv"] .watched-overlay')).toBeFalsy();
779
780
792
await waitFor(dom, () => !!dom.window.document.querySelector('.file-item[data-path="/data/watched-full.mkv"] .watched-overlay--fully'));
781
793
782
794
const fullOverlayPath = dom.window.document.querySelector('.file-item[data-path="/data/watched-full.mkv"] .watched-overlay--fully path');
@@ -159,6 +159,23 @@ describe('page load smoke test', () =>159
{
159
{
160
res.json({ ok: true, updated: true });
160
res.json({ ok: true, updated: true });
161
});
161
});
162
app.post('/api/files/watched-statuses', (req, res) =>
163
{
164
const requested = Array.isArray(req.body?.filePaths) ? req.body.filePaths : [];
165
const statuses = {};
166
167
for (const rawPath of requested)
168
{
169
const filePath = String(rawPath || '');
170
const allItems = Object.values(listFixture).flat();
171
const item = allItems.find((it) => it.path === filePath);
172
const watchedBy = metaWatchedByFixture[filePath] || (item && item.watchedBy) || {};
173
const status = String(watchedBy.tester || '').toLowerCase();
174
if (status === 'fully' || status === 'partway') statuses[filePath] = status;
175
}
176
177
res.json({ statuses });
178
});
162
app.get('/api/files/root-access', (req, res) =>
179
app.get('/api/files/root-access', (req, res) =>
163
{
180
{
164
const rootPath = String(req.query.rootPath || '');
181
const rootPath = String(req.query.rootPath || '');
@@ -768,15 +785,10 @@ describe('page load smoke test', () =>768
};
785
};
769
metaWatchedByFixture['/data/watched-full.mkv'] = { tester: 'fully' };
786
metaWatchedByFixture['/data/watched-full.mkv'] = { tester: 'fully' };
770
metaWatchedByFixture['/data/watched-part.mkv'] = { tester: 'partway' };
787
metaWatchedByFixture['/data/watched-part.mkv'] = { tester: 'partway' };
771
metaDelayMsFixture['/data/watched-full.mkv'] = 80;
772
metaDelayMsFixture['/data/watched-part.mkv'] = 80;
773
788
774
const { dom, runtimeErrors } = await bootClient();
789
const { dom, runtimeErrors } = await bootClient();
775
expect(runtimeErrors).toEqual([]);
790
expect(runtimeErrors).toEqual([]);
776
791
777
await waitFor(dom, () => !!dom.window.document.querySelector('.file-item[data-path="/data/watched-full.mkv"]'));
778
expect(dom.window.document.querySelector('.file-item[data-path="/data/watched-full.mkv"] .watched-overlay')).toBeFalsy();
779
780
await waitFor(dom, () => !!dom.window.document.querySelector('.file-item[data-path="/data/watched-full.mkv"] .watched-overlay--fully'));
792
await waitFor(dom, () => !!dom.window.document.querySelector('.file-item[data-path="/data/watched-full.mkv"] .watched-overlay--fully'));
781
793
782
const fullOverlayPath = dom.window.document.querySelector('.file-item[data-path="/data/watched-full.mkv"] .watched-overlay--fully path');
794
const fullOverlayPath = dom.window.document.querySelector('.file-item[data-path="/data/watched-full.mkv"] .watched-overlay--fully path');