fix: tmdb series and movies not caching

This commit is contained in:
Aleksi Lassila
2025-03-13 21:01:45 +02:00
parent bb08f5fd7e
commit f6f7fbe73d
4 changed files with 90 additions and 28 deletions

View File

@@ -25,6 +25,36 @@ export class MovieMetadata {
@ApiProperty({ type: 'string' })
@UpdateDateColumn()
updatedAt: Date;
/**
* Requires update before serving
*/
isOutdated() {
const releaseDate = this.tmdbMovie?.release_date;
if (!this.tmdbMovie) return true;
if (!this.updatedAt) return true;
if (
releaseDate &&
new Date() > new Date(releaseDate) &&
new Date(this.updatedAt) < new Date(releaseDate)
)
return true;
return false;
}
/**
* Can be lazily updated after serving
*/
isStale() {
if (this.isOutdated()) return true;
if (new Date().getTime() - this.updatedAt.getTime() > TMDB_CACHE_TTL)
return true;
return false;
}
}
@Entity()
@@ -45,19 +75,33 @@ export class SeriesMetadata {
@UpdateDateColumn()
updatedAt: Date;
isStale() {
/**
* Requires update before serving
*/
isOutdated() {
const nextAirDate = this.tmdbSeries?.next_episode_to_air?.air_date;
if (!this.tmdbSeries) return true;
if (!this.updatedAt) return true;
if (
nextAirDate &&
new Date() > new Date(nextAirDate) &&
new Date(this.updatedAt) < new Date(nextAirDate)
)
return true;
return false;
}
/**
* Can be lazily updated after serving
*/
isStale() {
if (this.isOutdated()) return true;
if (new Date().getTime() - this.updatedAt.getTime() > TMDB_CACHE_TTL)
return true;
if (
this.tmdbSeries?.next_episode_to_air?.air_date &&
new Date() > new Date(this.tmdbSeries.next_episode_to_air.air_date)
) {
return true;
}
return false;
}
}