Browse Source

Merge pull request #19380 from abpframework/salihozkara/docsCache

Docs: Improve clear cache
pull/19395/head
maliming 3 years ago
committed by GitHub
parent
commit
c2655344df
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 6
      modules/docs/src/Volo.Docs.Admin.Application/Volo/Docs/Admin/Documents/DocumentAdminAppService.cs
  2. 2
      modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/DocumentWithoutDetails.cs
  3. 3
      modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/IDocumentRepository.cs
  4. 7
      modules/docs/src/Volo.Docs.EntityFrameworkCore/Volo/Docs/Documents/EFCoreDocumentRepository.cs
  5. 14
      modules/docs/src/Volo.Docs.MongoDB/Volo/Docs/Documents/MongoDocumentRepository.cs
  6. 11
      modules/docs/test/Volo.Docs.TestBase/Volo/Docs/DocumentRepository_Tests.cs

6
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)

2
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; }

3
modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/IDocumentRepository.cs

@ -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,

7
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<List<Document>> GetListAsync(Guid? projectId, string version, string name, CancellationToken cancellationToken = default)
{
return await (await GetDbSetAsync())

14
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<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)

11
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));
}
}
}

Loading…
Cancel
Save