From 82cb2ea7608f5e0da08b2aa01f21b94ede2c3f2d Mon Sep 17 00:00:00 2001 From: Jurgis Sakalauskas Date: Mon, 12 Oct 2026 11:29:02 +0300 Subject: [PATCH] continue watching: only titles played in the last 3 months Imported history (Kodi's, years of it) would otherwise fill it with long abandoned shows and movies. Watched marks and resume points stay as they are. Co-Authored-By: Claude Opus 5.5 --- src/WatchState/watch-state.service.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/WatchState/watch-state.service.ts b/src/WatchState/watch-state.service.ts index 4980dae..db4338a 100644 --- a/src/WatchState/watch-state.service.ts +++ b/src/WatchState/watch-state.service.ts @@ -15,6 +15,8 @@ import { PlaybackReport } from './Dto/playback-report.dto'; const WATCHED_RATIO = 0.9; /** earlier positions don't move the resume point, so a quick open/close keeps it */ const MIN_POSITION = 10; +/** Continue watching only goes this far back, older activity doesn't crowd it */ +const CONTINUE_WATCHING_MONTHS = 3; export type WatchStates = Map; @@ -147,14 +149,18 @@ export class WatchStateService { /** * What to watch next, one file per title, latest activity first: the title's * last played file while it's unfinished, or for shows the next unwatched - * episode after it. Finished movies and shows are left out, and so are files - * hidden from Continue watching. + * episode after it. Only titles played in the last CONTINUE_WATCHING_MONTHS; + * finished movies and shows are left out, and so are files hidden from + * Continue watching. * Files come with their title and torrent. */ async getContinueWatching( states: WatchStates, limit = 20, ): Promise { + const since = new Date(); + since.setMonth(since.getMonth() - CONTINUE_WATCHING_MONTHS); + const fileEntities = await this.fileRepository .createQueryBuilder('file') .leftJoinAndSelect('file.title', 'title') @@ -164,8 +170,9 @@ export class WatchStateService { `file.title_id IN ( SELECT f.title_id FROM files f INNER JOIN watch_state s ON s.file_id = f.id - WHERE s.last_played IS NOT NULL + WHERE s.last_played >= :since )`, + { since: since.getTime() }, ) .getMany(); @@ -187,7 +194,8 @@ export class WatchStateService { const last = titleFiles.reduce((latest, fileEntity) => lastPlayed(fileEntity) >= lastPlayed(latest) ? fileEntity : latest, ); - if (lastPlayed(last) === 0) { + // (the recent activity may have been on a file deleted since) + if (lastPlayed(last) < since.getTime()) { return; }