@@ -2031,6 +2031,39 @@ private void PurgeCompany(int companyId, bool removeImageFiles = true)
2031
2031
2032
2032
#region People
2033
2033
2034
+ public async Task RepairMissingPeople ( )
2035
+ {
2036
+ var missingIds = new HashSet < int > ( ) ;
2037
+ var updateCount = 0 ;
2038
+ var skippedCount = 0 ;
2039
+
2040
+ var peopleIds = _tmdbPeople . GetAll ( ) . Select ( person => person . TmdbPersonID ) . ToHashSet ( ) ;
2041
+
2042
+ foreach ( var person in _tmdbEpisodeCast . GetAll ( ) )
2043
+ if ( ! peopleIds . Contains ( person . TmdbPersonID ) ) missingIds . Add ( person . TmdbPersonID ) ;
2044
+ foreach ( var person in _tmdbEpisodeCrew . GetAll ( ) )
2045
+ if ( ! peopleIds . Contains ( person . TmdbPersonID ) ) missingIds . Add ( person . TmdbPersonID ) ;
2046
+
2047
+ foreach ( var person in _tmdbMovieCast . GetAll ( ) )
2048
+ if ( ! peopleIds . Contains ( person . TmdbPersonID ) ) missingIds . Add ( person . TmdbPersonID ) ;
2049
+ foreach ( var person in _tmdbMovieCrew . GetAll ( ) )
2050
+ if ( ! peopleIds . Contains ( person . TmdbPersonID ) ) missingIds . Add ( person . TmdbPersonID ) ;
2051
+
2052
+ _logger . LogDebug ( "Found {@Count} unique missing TMDB People for Episode & Movie staff" , missingIds . Count ) ;
2053
+
2054
+ foreach ( var personId in missingIds )
2055
+ {
2056
+ var ( _, updated ) = await UpdatePerson ( personId , forceRefresh : true ) ;
2057
+ if ( updated )
2058
+ updateCount ++ ;
2059
+ else
2060
+ skippedCount ++ ;
2061
+ }
2062
+
2063
+ _logger . LogInformation ( "Updated missing TMDB People: Found/Updated/Skipped {@Found}/{@Updated}/{@Skipped}" ,
2064
+ missingIds . Count , updateCount , skippedCount ) ;
2065
+ }
2066
+
2034
2067
public async Task < ( bool added , bool updated ) > UpdatePerson ( int personId , bool forceRefresh = false , bool downloadImages = false )
2035
2068
{
2036
2069
using ( await GetLockForEntity ( ForeignEntityType . Person , personId , "metadata & images" , "Update" ) . ConfigureAwait ( false ) )
@@ -2048,6 +2081,12 @@ private void PurgeCompany(int companyId, bool removeImageFiles = true)
2048
2081
methods |= PersonMethods . Images ;
2049
2082
var newlyAdded = tmdbPerson . TMDB_PersonID is 0 ;
2050
2083
var person = await UseClient ( c => c . GetPersonAsync ( personId , methods ) , $ "Get person { personId } ") ;
2084
+ if ( person is null )
2085
+ {
2086
+ _logger . LogDebug ( "Unable to update staff; Scheduling refresh of related links. (Person={PersonId})" , personId ) ;
2087
+ await ScheduleUpdateMoviesAndShowsByPerson ( personId ) ;
2088
+ return ( false , false ) ;
2089
+ }
2051
2090
var updated = tmdbPerson . Populate ( person ) ;
2052
2091
if ( updated )
2053
2092
{
@@ -2062,6 +2101,28 @@ private void PurgeCompany(int companyId, bool removeImageFiles = true)
2062
2101
}
2063
2102
}
2064
2103
2104
+ private async Task ScheduleUpdateMoviesAndShowsByPerson ( int tmdbPersonId )
2105
+ {
2106
+ var showIds = new HashSet < int > ( ) ;
2107
+ var movieIds = new HashSet < int > ( ) ;
2108
+
2109
+ foreach ( var staff in _tmdbEpisodeCast . GetByTmdbPersonID ( tmdbPersonId ) )
2110
+ showIds . Add ( staff . TmdbShowID ) ;
2111
+ foreach ( var staff in _tmdbEpisodeCrew . GetByTmdbPersonID ( tmdbPersonId ) )
2112
+ showIds . Add ( staff . TmdbShowID ) ;
2113
+
2114
+ foreach ( var staff in _tmdbMovieCast . GetByTmdbPersonID ( tmdbPersonId ) )
2115
+ movieIds . Add ( staff . TmdbMovieID ) ;
2116
+ foreach ( var staff in _tmdbMovieCrew . GetByTmdbPersonID ( tmdbPersonId ) )
2117
+ movieIds . Add ( staff . TmdbMovieID ) ;
2118
+
2119
+ foreach ( var showId in showIds )
2120
+ await ScheduleUpdateOfShow ( showId , downloadCrewAndCast : true , forceRefresh : true ) ;
2121
+
2122
+ foreach ( var movieId in movieIds )
2123
+ await ScheduleUpdateOfMovie ( movieId , downloadCrewAndCast : true , forceRefresh : true ) ;
2124
+ }
2125
+
2065
2126
private async Task DownloadPersonImages ( int personId , ProfileImages images , bool forceDownload = false )
2066
2127
{
2067
2128
var settings = _settingsProvider . GetSettings ( ) ;
0 commit comments