mirror of
https://github.com/chrisbenincasa/tunarr.git
synced 2026-04-18 09:03:35 -04:00
fix: backdate initial guide generation at startup
This commit is contained in:
@@ -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,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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(),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user