Browse Source
Merge pull request #19380 from abpframework/salihozkara/docsCache
Docs: Improve clear cache
pull/19395/head
maliming
3 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with
37 additions and
6 deletions
-
modules/docs/src/Volo.Docs.Admin.Application/Volo/Docs/Admin/Documents/DocumentAdminAppService.cs
-
modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/DocumentWithoutDetails.cs
-
modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/IDocumentRepository.cs
-
modules/docs/src/Volo.Docs.EntityFrameworkCore/Volo/Docs/Documents/EFCoreDocumentRepository.cs
-
modules/docs/src/Volo.Docs.MongoDB/Volo/Docs/Documents/MongoDocumentRepository.cs
-
modules/docs/test/Volo.Docs.TestBase/Volo/Docs/DocumentRepository_Tests.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) |
|
|
|
|
|
|
|
@ -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; } |
|
|
|
|
|
|
|
|
|
|
|
@ -12,6 +12,9 @@ namespace Volo.Docs.Documents |
|
|
|
Task<List<DocumentInfo>> GetUniqueListDocumentInfoAsync(CancellationToken cancellationToken = default); |
|
|
|
|
|
|
|
Task<List<Document>> GetListByProjectId(Guid projectId, CancellationToken cancellationToken = default); |
|
|
|
|
|
|
|
Task UpdateProjectLastCachedTimeAsync(Guid projectId, DateTime cachedTime, |
|
|
|
CancellationToken cancellationToken = default); |
|
|
|
|
|
|
|
Task<Document> FindAsync(Guid projectId, |
|
|
|
string name, |
|
|
|
|
|
|
|
@ -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<List<Document>> GetListAsync(Guid? projectId, string version, string name, CancellationToken cancellationToken = default) |
|
|
|
{ |
|
|
|
return await (await GetDbSetAsync()) |
|
|
|
|
|
|
|
@ -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<Document>.Filter.Eq(x => x.ProjectId, projectId), |
|
|
|
Builders<Document>.Update.Set(x => x.LastCachedTime, cachedTime), |
|
|
|
cancellationToken: GetCancellationToken(cancellationToken) |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
public virtual async Task<Document> FindAsync(Guid projectId, string name, string languageCode, string version, |
|
|
|
bool includeDetails = true, |
|
|
|
CancellationToken cancellationToken = default) |
|
|
|
|
|
|
|
@ -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)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|