From 9ab26976c2794cd49f26fb4a3b1b81c445c61e47 Mon Sep 17 00:00:00 2001 From: Christian Benincasa Date: Sat, 11 Apr 2026 09:00:32 -0400 Subject: [PATCH] fix: backdate initial guide generation at startup --- server/src/services/TvGuideService.ts | 14 ++++++++++++-- server/src/tasks/UpdateXmlTvTask.ts | 15 ++++++++++++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/server/src/services/TvGuideService.ts b/server/src/services/TvGuideService.ts index 6c35af0f..a69f2271 100644 --- a/server/src/services/TvGuideService.ts +++ b/server/src/services/TvGuideService.ts @@ -189,7 +189,11 @@ export class TVGuideService { ); } - async buildAllChannels(guideDuration: Duration, force: boolean = false) { + async buildAllChannels( + guideDuration: Duration, + force: boolean = false, + startTime: number = +dayjs(), + ) { return this.withGuideContext(async () => { if (isEmpty(this.channelsById)) { const placeholderChannel = await this.makePlaceholderChannel(); @@ -198,7 +202,13 @@ export class TVGuideService { delete this.cachedGuide[PlaceholderChannelId]; await Promise.all( keys(this.channelsById).map((channelId) => - this.buildChannelGuide(guideDuration, channelId, false, force), + this.buildChannelGuide( + guideDuration, + channelId, + false, + force, + startTime, + ), ), ); } diff --git a/server/src/tasks/UpdateXmlTvTask.ts b/server/src/tasks/UpdateXmlTvTask.ts index 745ffcb3..15d4f43b 100644 --- a/server/src/tasks/UpdateXmlTvTask.ts +++ b/server/src/tasks/UpdateXmlTvTask.ts @@ -84,9 +84,22 @@ export class UpdateXmlTvTask extends Task2 { true, ); } else { + // Round start time down to the nearest hour so guide boundaries align + // with the hour-granular requests made by the UI and other consumers. + // Extend the duration by the fractional hour we went back so the guide + // end time — and therefore coverage before the next scheduled run — is + // identical to what it would have been without rounding. + const now = dayjs(); + const startTime = now.startOf('hour'); + const extraDuration = dayjs.duration(now.diff(startTime)); + const guideDuration = dayjs + .duration({ hours: xmltvSettings.programmingHours }) + .add(extraDuration); + await this.guideService.buildAllChannels( - dayjs.duration({ hours: xmltvSettings.programmingHours }), + guideDuration, false, + startTime.valueOf(), ); }