fix(watchlist-sync): handle empty watchlists on PostgreSQL (#2718)

This commit is contained in:
Angelo Olivera
2026-03-23 07:55:40 -06:00
committed by GitHub
parent dbe1fca6a9
commit 865396fd28
2 changed files with 18 additions and 8 deletions

View File

@@ -97,7 +97,12 @@ export const startJobs = (): void => {
logger.info('Starting scheduled job: Plex Watchlist Sync', { logger.info('Starting scheduled job: Plex Watchlist Sync', {
label: 'Jobs', label: 'Jobs',
}); });
watchlistSync.syncWatchlist(); watchlistSync.syncWatchlist().catch((e) => {
logger.error('Failed to sync watchlists', {
label: 'Plex Watchlist Sync',
errorMessage: e.message,
});
});
}), }),
}); });
} else if ( } else if (

View File

@@ -76,13 +76,18 @@ class WatchlistSync {
const watchlistTmdbIds = response.items.map((i) => i.tmdbId); const watchlistTmdbIds = response.items.map((i) => i.tmdbId);
const requestRepository = getRepository(MediaRequest); const requestRepository = getRepository(MediaRequest);
const existingAutoRequests = await requestRepository const existingAutoRequests: MediaRequest[] =
watchlistTmdbIds.length > 0
? await requestRepository
.createQueryBuilder('request') .createQueryBuilder('request')
.leftJoinAndSelect('request.media', 'media') .leftJoinAndSelect('request.media', 'media')
.where('request.requestedBy = :userId', { userId: user.id }) .where('request.requestedBy = :userId', { userId: user.id })
.andWhere('request.isAutoRequest = true') .andWhere('request.isAutoRequest = true')
.andWhere('media.tmdbId IN (:...tmdbIds)', { tmdbIds: watchlistTmdbIds }) .andWhere('media.tmdbId IN (:...tmdbIds)', {
.getMany(); tmdbIds: watchlistTmdbIds,
})
.getMany()
: [];
const autoRequestedTmdbIds = new Set( const autoRequestedTmdbIds = new Set(
existingAutoRequests existingAutoRequests