diff --git a/modules/docs/src/Volo.Docs.Admin.Application/Volo/Docs/Admin/Documents/DocumentAdminAppService.cs b/modules/docs/src/Volo.Docs.Admin.Application/Volo/Docs/Admin/Documents/DocumentAdminAppService.cs index 9356ba9c38..8e70be19e4 100644 --- a/modules/docs/src/Volo.Docs.Admin.Application/Volo/Docs/Admin/Documents/DocumentAdminAppService.cs +++ b/modules/docs/src/Volo.Docs.Admin.Application/Volo/Docs/Admin/Documents/DocumentAdminAppService.cs @@ -57,7 +57,7 @@ namespace Volo.Docs.Admin.Documents var versionCacheKey = CacheKeyGenerator.GenerateProjectVersionsCacheKey(project); await _versionCache.RemoveAsync(versionCacheKey, true); - var documents = await _documentRepository.GetListByProjectId(project.Id); + var documents = await _documentRepository.GetListWithoutDetailsByProjectId(project.Id); var documentUpdateInfoCacheKeys = documents.Select(document => CacheKeyGenerator.GenerateDocumentUpdateInfoCacheKey( @@ -69,10 +69,8 @@ namespace Volo.Docs.Admin.Documents ); await _documentUpdateCache.RemoveManyAsync(documentUpdateInfoCacheKeys); - - documents.ForEach(document => document.LastCachedTime = DateTime.MinValue); - await _documentRepository.UpdateManyAsync(documents); + await _documentRepository.UpdateProjectLastCachedTimeAsync(project.Id, DateTime.MinValue); } public virtual async Task PullAllAsync(PullAllDocumentInput input) diff --git a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/DocumentWithoutDetails.cs b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/DocumentWithoutDetails.cs index 8adade5be2..2aaf54aee4 100644 --- a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/DocumentWithoutDetails.cs +++ b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/DocumentWithoutDetails.cs @@ -5,6 +5,8 @@ namespace Volo.Docs.Documents public class DocumentWithoutDetails { public Guid Id { get; set; } + + public string Name { get; set; } public virtual string Version { get; set; } diff --git a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/IDocumentRepository.cs b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/IDocumentRepository.cs index b1580f379a..7dc8f13147 100644 --- a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/IDocumentRepository.cs +++ b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/IDocumentRepository.cs @@ -12,6 +12,9 @@ namespace Volo.Docs.Documents Task> GetUniqueListDocumentInfoAsync(CancellationToken cancellationToken = default); Task> GetListByProjectId(Guid projectId, CancellationToken cancellationToken = default); + + Task UpdateProjectLastCachedTimeAsync(Guid projectId, DateTime cachedTime, + CancellationToken cancellationToken = default); Task FindAsync(Guid projectId, string name, diff --git a/modules/docs/src/Volo.Docs.EntityFrameworkCore/Volo/Docs/Documents/EFCoreDocumentRepository.cs b/modules/docs/src/Volo.Docs.EntityFrameworkCore/Volo/Docs/Documents/EFCoreDocumentRepository.cs index 700203e7dd..1120e36d01 100644 --- a/modules/docs/src/Volo.Docs.EntityFrameworkCore/Volo/Docs/Documents/EFCoreDocumentRepository.cs +++ b/modules/docs/src/Volo.Docs.EntityFrameworkCore/Volo/Docs/Documents/EFCoreDocumentRepository.cs @@ -28,6 +28,7 @@ namespace Volo.Docs.Documents Version = x.Version, LanguageCode = x.LanguageCode, Format = x.Format, + Name = x.Name }) .ToListAsync(GetCancellationToken(cancellationToken)); } @@ -55,6 +56,12 @@ namespace Volo.Docs.Documents return await (await GetDbSetAsync()).Where(d => d.ProjectId == projectId).ToListAsync(GetCancellationToken(cancellationToken)); } + public async Task UpdateProjectLastCachedTimeAsync(Guid projectId, DateTime cachedTime, + CancellationToken cancellationToken = default) + { + await (await GetDbSetAsync()).Where(d => d.ProjectId == projectId).ExecuteUpdateAsync(x => x.SetProperty(d => d.LastCachedTime, cachedTime), GetCancellationToken(cancellationToken)); + } + public virtual async Task> GetListAsync(Guid? projectId, string version, string name, CancellationToken cancellationToken = default) { return await (await GetDbSetAsync()) diff --git a/modules/docs/src/Volo.Docs.MongoDB/Volo/Docs/Documents/MongoDocumentRepository.cs b/modules/docs/src/Volo.Docs.MongoDB/Volo/Docs/Documents/MongoDocumentRepository.cs index 1cd93545a5..9a3750deb0 100644 --- a/modules/docs/src/Volo.Docs.MongoDB/Volo/Docs/Documents/MongoDocumentRepository.cs +++ b/modules/docs/src/Volo.Docs.MongoDB/Volo/Docs/Documents/MongoDocumentRepository.cs @@ -29,7 +29,8 @@ namespace Volo.Docs.Documents Id = x.Id, Version = x.Version, LanguageCode = x.LanguageCode, - Format = x.Format + Format = x.Format, + Name = x.Name }) .ToListAsync(GetCancellationToken(cancellationToken)); } @@ -53,6 +54,17 @@ namespace Volo.Docs.Documents return await (await GetMongoQueryableAsync(cancellationToken)).Where(d => d.ProjectId == projectId).ToListAsync(GetCancellationToken(cancellationToken)); } + public async Task UpdateProjectLastCachedTimeAsync(Guid projectId, DateTime cachedTime, + CancellationToken cancellationToken = default) + { + var collection = await GetCollectionAsync(cancellationToken); + await collection.UpdateManyAsync( + Builders.Filter.Eq(x => x.ProjectId, projectId), + Builders.Update.Set(x => x.LastCachedTime, cachedTime), + cancellationToken: GetCancellationToken(cancellationToken) + ); + } + public virtual async Task FindAsync(Guid projectId, string name, string languageCode, string version, bool includeDetails = true, CancellationToken cancellationToken = default) diff --git a/modules/docs/test/Volo.Docs.TestBase/Volo/Docs/DocumentRepository_Tests.cs b/modules/docs/test/Volo.Docs.TestBase/Volo/Docs/DocumentRepository_Tests.cs index ed0769ccc1..742f80fe17 100644 --- a/modules/docs/test/Volo.Docs.TestBase/Volo/Docs/DocumentRepository_Tests.cs +++ b/modules/docs/test/Volo.Docs.TestBase/Volo/Docs/DocumentRepository_Tests.cs @@ -1,4 +1,5 @@ -using System.Threading.Tasks; +using System; +using System.Threading.Tasks; using Shouldly; using Volo.Abp.Modularity; using Volo.Docs.Documents; @@ -34,5 +35,13 @@ namespace Volo.Docs (await DocumentRepository.GetListAsync()).ShouldBeEmpty(); } + + [Fact] + public async Task UpdateProjectLastCachedTimeAsync() + { + await DocumentRepository.UpdateProjectLastCachedTimeAsync(DocsTestData.ProjectId, DateTime.MinValue); + var documentsAfterClear = await DocumentRepository.GetListByProjectId(DocsTestData.ProjectId); + documentsAfterClear.ForEach(d => d.LastCachedTime.ShouldBe(DateTime.MinValue)); + } } }