From 390000d6d45ff2c4f60476dab567645787ac9e5a Mon Sep 17 00:00:00 2001 From: Brandon Date: Fri, 12 May 2023 11:52:30 -0400 Subject: [PATCH] fix: base scanner will set requests to completed correctly --- server/lib/availabilitySync.ts | 1 + server/lib/scanners/baseScanner.ts | 68 ++++++++++++++++--- .../RequestModal/CollectionRequestModal.tsx | 3 - 3 files changed, 59 insertions(+), 13 deletions(-) diff --git a/server/lib/availabilitySync.ts b/server/lib/availabilitySync.ts index 398701bc4..ea115c538 100644 --- a/server/lib/availabilitySync.ts +++ b/server/lib/availabilitySync.ts @@ -238,6 +238,7 @@ class AvailabilitySync { where: whereOptions, skip: offset, take: pageSize, + order: { id: 'DESC' }, })); offset += pageSize; } while (mediaPage.length > 0); diff --git a/server/lib/scanners/baseScanner.ts b/server/lib/scanners/baseScanner.ts index 26f26dafb..25d3898cc 100644 --- a/server/lib/scanners/baseScanner.ts +++ b/server/lib/scanners/baseScanner.ts @@ -13,6 +13,7 @@ import { getSettings } from '@server/lib/settings'; import logger from '@server/logger'; import AsyncLock from '@server/utils/asyncLock'; import { randomUUID } from 'crypto'; +import { In } from 'typeorm'; // Default scan rates (can be overidden) const BUNDLE_SIZE = 20; @@ -98,17 +99,25 @@ class BaseScanner { private async requestUpdater(mediaId: number, is4k: boolean) { const requestRepository = getRepository(MediaRequest); - const request = await requestRepository.findOne({ + const request = await requestRepository.find({ relations: { media: true, }, - where: { media: { id: mediaId }, is4k: is4k }, + where: { + media: { id: mediaId }, + is4k: is4k, + status: MediaRequestStatus.APPROVED, + }, }); - await requestRepository.update( - { id: request?.id }, - { status: MediaRequestStatus.COMPLETED } - ); + const requestIds = request.map((request) => request.id); + + if (requestIds.length > 0) { + await requestRepository.update( + { id: In(requestIds) }, + { status: MediaRequestStatus.COMPLETED } + ); + } } private async seasonRequestUpdater( @@ -369,7 +378,7 @@ class BaseScanner { ? MediaStatus.PARTIALLY_AVAILABLE : season.is4kOverride && season.processing && - existingSeason.status !== MediaStatus.DELETED + existingSeason.status4k !== MediaStatus.DELETED ? MediaStatus.PROCESSING : existingSeason.status4k; @@ -516,7 +525,6 @@ class BaseScanner { season.status4k !== MediaStatus.UNKNOWN && season.status4k !== MediaStatus.DELETED ).length === 0; - media.status = isAllStandardSeasons || shouldStayAvailable ? MediaStatus.AVAILABLE @@ -553,11 +561,51 @@ class BaseScanner { ? MediaStatus.DELETED : MediaStatus.UNKNOWN; - if (isAllStandardSeasons) { + const seasonsCompleted = + seasons.length && + seasons.filter( + (season) => + season.episodes === season.totalEpisodes && season.episodes > 0 + ).length; + + const seasonsCompleted4k = + seasons.length && + seasons.filter( + (season) => + season.episodes4k === season.totalEpisodes && + season.episodes4k > 0 + ).length; + + const seasonRequestRepository = getRepository(SeasonRequest); + + const seasonRequestsCompleted = await seasonRequestRepository.find({ + relations: { + request: { + media: true, + }, + }, + where: { + request: { + is4k: is4k, + media: { + id: media.id, + }, + }, + status: MediaRequestStatus.COMPLETED, + }, + }); + + if ( + seasonsCompleted === seasonRequestsCompleted.length && + seasonRequestsCompleted.length > 0 + ) { this.requestUpdater(media.id, false); } - if (isAll4kSeasons) { + if ( + seasonsCompleted4k === seasonRequestsCompleted.length && + seasonRequestsCompleted.length > 0 + ) { this.requestUpdater(media.id, true); } await mediaRepository.save(media); diff --git a/src/components/RequestModal/CollectionRequestModal.tsx b/src/components/RequestModal/CollectionRequestModal.tsx index 75d7b8f47..b650d07db 100644 --- a/src/components/RequestModal/CollectionRequestModal.tsx +++ b/src/components/RequestModal/CollectionRequestModal.tsx @@ -244,9 +244,6 @@ const CollectionRequestModal = ({ { type: 'or' } ); - console.log('getALL', getAllRequestedParts().includes(8011)); - console.log('getPART', getPartRequest(8011)); - return (