fix: backdate initial guide generation at startup

This commit is contained in:
Christian Benincasa
2026-04-11 09:00:32 -04:00
parent b62507274d
commit 9ab26976c2
2 changed files with 26 additions and 3 deletions

View File

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

View File

@@ -84,9 +84,22 @@ export class UpdateXmlTvTask extends Task2<typeof UpdateXmlTvTaskRequest> {
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(),
);
}