From aed8e9044721ad7af13dc1eb1ee9aa45772acb8d Mon Sep 17 00:00:00 2001 From: Salih Date: Thu, 20 Jun 2024 13:34:53 +0300 Subject: [PATCH] Fix index problem --- .../Volo/Docs/Documents/DocumentAppService.cs | 16 +++++++++++++--- .../GitHub/Documents/GithubDocumentSource.cs | 12 ------------ 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/modules/docs/src/Volo.Docs.Application/Volo/Docs/Documents/DocumentAppService.cs b/modules/docs/src/Volo.Docs.Application/Volo/Docs/Documents/DocumentAppService.cs index 0fe6c18699..8489869037 100644 --- a/modules/docs/src/Volo.Docs.Application/Volo/Docs/Documents/DocumentAppService.cs +++ b/modules/docs/src/Volo.Docs.Application/Volo/Docs/Documents/DocumentAppService.cs @@ -383,12 +383,22 @@ namespace Volo.Docs.Documents return await GetDocumentAsync(documentName, project, languageCode, version); } - if (document.LastCachedTime + _cacheTimeout < DateTime.Now) + if (document.LastCachedTime + _cacheTimeout >= DateTime.Now) { - return await GetDocumentAsync(documentName, project, languageCode, version, document); + return CreateDocumentWithDetailsDto(project, document); } - return CreateDocumentWithDetailsDto(project, document); + try + { + return await GetDocumentAsync(documentName, project, languageCode, version, document); + } + catch + { + Logger.LogWarning( + "Could not retrieve the document ({documentName}, {languageCode}, {version}) from the source. Using the cached version.", + documentName, languageCode, version); + return CreateDocumentWithDetailsDto(project, document); + } } protected virtual DocumentWithDetailsDto CreateDocumentWithDetailsDto(Project project, Document document) diff --git a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/GithubDocumentSource.cs b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/GithubDocumentSource.cs index 21ae3a460c..3698d5583e 100644 --- a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/GithubDocumentSource.cs +++ b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/GithubDocumentSource.cs @@ -410,18 +410,6 @@ namespace Volo.Docs.GitHub.Documents return await _githubRepositoryManager.GetFileRawStringContentAsync(rawDocumentUrl, token, userAgent); } - catch (HttpRequestException ex) - { - Logger.LogWarning($"Could not retrieve the document ({rawDocumentUrl}) from Github. Trying to get it from database..."); - - var document = await _documentRepository.FindAsync(project.Id, documentName, languageCode, version); - if (document == null) - { - throw new DocumentNotFoundException(rawDocumentUrl); - } - - return document.Content; - } catch (Exception ex) { //TODO: Only handle when document is really not available