@@ -19,6 +19,7 @@ public class GitHubApiRepositoriesService
1919 readonly IAnalyticsService _analyticsService ;
2020 readonly GitHubUserService _gitHubUserService ;
2121 readonly GitHubApiV3Service _gitHubApiV3Service ;
22+ readonly RepositoryDatabase _repositoryDatabase ;
2223 readonly ReferringSitesDatabase _referringSitesDatabase ;
2324 readonly GitHubApiStatusService _gitHubApiStatusService ;
2425 readonly GitHubGraphQLApiService _gitHubGraphQLApiService ;
@@ -27,6 +28,7 @@ public GitHubApiRepositoriesService(FavIconService favIconService,
2728 IAnalyticsService analyticsService ,
2829 GitHubUserService gitHubUserService ,
2930 GitHubApiV3Service gitHubApiV3Service ,
31+ RepositoryDatabase repositoryDatabase ,
3032 ReferringSitesDatabase referringSitesDatabase ,
3133 GitHubApiStatusService gitHubApiStatusService ,
3234 GitHubGraphQLApiService gitHubGraphQLApiService )
@@ -35,6 +37,7 @@ public GitHubApiRepositoriesService(FavIconService favIconService,
3537 _analyticsService = analyticsService ;
3638 _gitHubUserService = gitHubUserService ;
3739 _gitHubApiV3Service = gitHubApiV3Service ;
40+ _repositoryDatabase = repositoryDatabase ;
3841 _referringSitesDatabase = referringSitesDatabase ;
3942 _gitHubApiStatusService = gitHubApiStatusService ;
4043 _gitHubGraphQLApiService = gitHubGraphQLApiService ;
@@ -138,9 +141,9 @@ public async IAsyncEnumerable<Repository> UpdateRepositoriesWithViewsClonesAndSt
138141 await getCloneStatisticsTask . ConfigureAwait ( false ) ,
139142 await getStarGazrsTask . ConfigureAwait ( false ) ) ;
140143 }
141- catch ( ApiException e ) when ( _gitHubApiStatusService . IsAbuseRateLimit ( e . Headers , out var timespan ) && timespan is TimeSpan retryTimeSpan )
144+ catch ( ApiException e ) when ( _gitHubApiStatusService . IsAbuseRateLimit ( e . Headers , out var timespan ) )
142145 {
143- OnAbuseRateLimitFound_UpdateRepositoriesWithViewsClonesAndStarsData ( repository , retryTimeSpan ) ;
146+ OnAbuseRateLimitFound_UpdateRepositoriesWithViewsClonesAndStarsData ( repository , timespan . Value ) ;
144147
145148 return ( null , null , null ) ;
146149 }
@@ -155,6 +158,17 @@ await getCloneStatisticsTask.ConfigureAwait(false),
155158 reportException ( e ) ;
156159
157160 return ( null , null , null ) ;
161+ }
162+ catch ( ApiException e ) when ( e . StatusCode is System . Net . HttpStatusCode . NotFound ) // Repository deleted from GitHub but has not yet been deleted from local SQLite Database
163+ {
164+ reportException ( e ) ;
165+
166+ var repositoryFromDatabase = await _repositoryDatabase . GetRepository ( repository . Url ) . ConfigureAwait ( false ) ;
167+ if ( repositoryFromDatabase is null )
168+ throw ;
169+
170+ await _repositoryDatabase . DeleteRepository ( repository ) . ConfigureAwait ( false ) ;
171+ return ( null , null , null ) ;
158172 }
159173
160174 void reportException ( in Exception e )
0 commit comments