Browse Source

Fix reindex problem

pull/19701/head
Salih 2 years ago
parent
commit
ef985630af
  1. 28
      modules/docs/src/Volo.Docs.Admin.Application/Volo/Docs/Admin/Projects/ProjectAdminAppService.cs
  2. 4
      modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/IDocumentRepository.cs
  3. 11
      modules/docs/src/Volo.Docs.EntityFrameworkCore/Volo/Docs/Documents/EFCoreDocumentRepository.cs
  4. 15
      modules/docs/src/Volo.Docs.MongoDB/Volo/Docs/Documents/MongoDocumentRepository.cs

28
modules/docs/src/Volo.Docs.Admin.Application/Volo/Docs/Admin/Projects/ProjectAdminAppService.cs

@ -134,15 +134,29 @@ namespace Volo.Docs.Admin.Projects
{
throw new Exception("Cannot find the project with the Id " + projectId);
}
var docs = (await _documentRepository.GetListByProjectId(project.Id))
.Where(doc => doc.FileName != project.NavigationDocumentName && doc.FileName != project.ParametersDocumentName)
.ToList();
await _elasticSearchService.DeleteAllByProjectIdAsync(project.Id);
if(docs.Any())
var docsCount = await _documentRepository.GetCountByProjectId(projectId);
if (docsCount == 0)
{
return;
}
const int maxResultCount = 1000;
var skipCount = 0;
while(skipCount < docsCount)
{
await _elasticSearchService.AddOrUpdateManyAsync(docs);
var docs = await _documentRepository.GetListByProjectId(projectId, skipCount, maxResultCount);
docs = docs.Where(doc => doc.FileName != project.NavigationDocumentName && doc.FileName != project.ParametersDocumentName).ToList();
if (!docs.Any())
{
return;
}
await _elasticSearchService.AddOrUpdateManyAsync(docs);
skipCount += maxResultCount;
}
}

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

@ -13,6 +13,10 @@ namespace Volo.Docs.Documents
Task<List<Document>> GetListByProjectId(Guid projectId, CancellationToken cancellationToken = default);
Task<List<Document>> GetListByProjectId(Guid projectId, int skipCount, int maxResultCount, CancellationToken cancellationToken = default);
Task<long> GetCountByProjectId(Guid projectId, CancellationToken cancellationToken = default);
Task UpdateProjectLastCachedTimeAsync(Guid projectId, DateTime cachedTime,
CancellationToken cancellationToken = default);

11
modules/docs/src/Volo.Docs.EntityFrameworkCore/Volo/Docs/Documents/EFCoreDocumentRepository.cs

@ -56,6 +56,17 @@ namespace Volo.Docs.Documents
return await (await GetDbSetAsync()).Where(d => d.ProjectId == projectId).ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<Document>> GetListByProjectId(Guid projectId, int skipCount, int maxResultCount,
CancellationToken cancellationToken = default)
{
return await (await GetDbSetAsync()).Where(d => d.ProjectId == projectId).PageBy(skipCount, maxResultCount).ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<long> GetCountByProjectId(Guid projectId, CancellationToken cancellationToken = default)
{
return await (await GetDbSetAsync()).Where(d => d.ProjectId == projectId).LongCountAsync(GetCancellationToken(cancellationToken));
}
public async Task UpdateProjectLastCachedTimeAsync(Guid projectId, DateTime cachedTime,
CancellationToken cancellationToken = default)
{

15
modules/docs/src/Volo.Docs.MongoDB/Volo/Docs/Documents/MongoDocumentRepository.cs

@ -54,6 +54,21 @@ namespace Volo.Docs.Documents
return await (await GetMongoQueryableAsync(cancellationToken)).Where(d => d.ProjectId == projectId).ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<Document>> GetListByProjectId(Guid projectId, int skipCount, int maxResultCount,
CancellationToken cancellationToken = default)
{
return await (await GetMongoQueryableAsync(cancellationToken)).Where(d => d.ProjectId == projectId)
.OrderBy(x => x.Name)
.Skip(skipCount)
.Take(maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<long> GetCountByProjectId(Guid projectId, CancellationToken cancellationToken = default)
{
return await (await GetMongoQueryableAsync(cancellationToken)).LongCountAsync(x => x.ProjectId == projectId, GetCancellationToken(cancellationToken));
}
public async Task UpdateProjectLastCachedTimeAsync(Guid projectId, DateTime cachedTime,
CancellationToken cancellationToken = default)
{

Loading…
Cancel
Save