forked from ddrilling/AsbCloudServer
Добавление записей в кэш для каждой скважины
This commit is contained in:
parent
787fd478eb
commit
aa5c67d2e7
@ -109,71 +109,64 @@ public class WellOperationRepository : CrudRepositoryBase<WellOperationBaseDto,
|
|||||||
|
|
||||||
public async Task<IEnumerable<SectionByOperationsDto>> GetSectionsAsync(IEnumerable<int> idsWells, CancellationToken token)
|
public async Task<IEnumerable<SectionByOperationsDto>> GetSectionsAsync(IEnumerable<int> idsWells, CancellationToken token)
|
||||||
{
|
{
|
||||||
var keyCacheSections = $"OperationsBySectionSummaries_{string.Join('_', idsWells.OrderBy(x => x))}";
|
const string keyCacheTemplate = "OperationsBySectionSummaries_{0}";
|
||||||
|
|
||||||
var cache = await memoryCache.GetOrCreateAsync(keyCacheSections, async (entry) =>
|
var result = new List<SectionByOperationsDto>();
|
||||||
|
|
||||||
|
foreach (var idWell in idsWells)
|
||||||
{
|
{
|
||||||
entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(30);
|
var sections = await memoryCache.GetOrCreateAsync(string.Format(keyCacheTemplate, idWell), async (entry) =>
|
||||||
|
{
|
||||||
|
entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(30);
|
||||||
|
|
||||||
var query = dbContext.Set<WellOperation>()
|
var query = dbContext.Set<WellOperation>()
|
||||||
.GroupBy(operation => new
|
.Where(x => x.IdWell == idWell)
|
||||||
{
|
.GroupBy(operation => new
|
||||||
operation.IdWell,
|
{
|
||||||
operation.IdType,
|
operation.IdType, operation.IdWellSectionType, operation.WellSectionType.Caption,
|
||||||
operation.IdWellSectionType,
|
})
|
||||||
operation.WellSectionType.Caption,
|
.Select(group => new
|
||||||
})
|
{
|
||||||
.Select(group => new
|
group.Key.IdType,
|
||||||
{
|
group.Key.IdWellSectionType,
|
||||||
group.Key.IdWell,
|
group.Key.Caption,
|
||||||
group.Key.IdType,
|
First = group
|
||||||
group.Key.IdWellSectionType,
|
.OrderBy(operation => operation.DateStart)
|
||||||
group.Key.Caption,
|
.Select(operation => new { operation.DateStart, operation.DepthStart, })
|
||||||
|
.First(),
|
||||||
|
Last = group
|
||||||
|
.OrderByDescending(operation => operation.DateStart)
|
||||||
|
.Select(operation => new
|
||||||
|
{
|
||||||
|
operation.DateStart, operation.DurationHours, operation.DepthEnd,
|
||||||
|
})
|
||||||
|
.First(),
|
||||||
|
});
|
||||||
|
|
||||||
First = group
|
var dbData = await query.ToArrayAsync(token);
|
||||||
.OrderBy(operation => operation.DateStart)
|
|
||||||
.Select(operation => new
|
|
||||||
{
|
|
||||||
operation.DateStart,
|
|
||||||
operation.DepthStart,
|
|
||||||
})
|
|
||||||
.First(),
|
|
||||||
|
|
||||||
Last = group
|
var sections = dbData.Select(
|
||||||
.OrderByDescending(operation => operation.DateStart)
|
|
||||||
.Select(operation => new
|
|
||||||
{
|
|
||||||
operation.DateStart,
|
|
||||||
operation.DurationHours,
|
|
||||||
operation.DepthEnd,
|
|
||||||
})
|
|
||||||
.First(),
|
|
||||||
})
|
|
||||||
.Where(s => idsWells.Contains(s.IdWell));
|
|
||||||
var dbData = await query.ToArrayAsync(token);
|
|
||||||
var sections = dbData.Select(
|
|
||||||
item => new SectionByOperationsDto
|
item => new SectionByOperationsDto
|
||||||
{
|
{
|
||||||
IdWell = item.IdWell,
|
IdWell = idWell,
|
||||||
IdType = item.IdType,
|
IdType = item.IdType,
|
||||||
IdWellSectionType = item.IdWellSectionType,
|
IdWellSectionType = item.IdWellSectionType,
|
||||||
|
|
||||||
Caption = item.Caption,
|
Caption = item.Caption,
|
||||||
|
|
||||||
DateStart = item.First.DateStart,
|
DateStart = item.First.DateStart,
|
||||||
DepthStart = item.First.DepthStart,
|
DepthStart = item.First.DepthStart,
|
||||||
|
|
||||||
DateEnd = item.Last.DateStart.AddHours(item.Last.DurationHours),
|
DateEnd = item.Last.DateStart.AddHours(item.Last.DurationHours),
|
||||||
DepthEnd = item.Last.DepthEnd,
|
DepthEnd = item.Last.DepthEnd,
|
||||||
})
|
});
|
||||||
.ToArray()
|
|
||||||
.AsEnumerable();
|
|
||||||
|
|
||||||
entry.Value = sections;
|
|
||||||
return sections;
|
|
||||||
});
|
|
||||||
|
|
||||||
return cache!;
|
entry.Value = sections;
|
||||||
|
return sections;
|
||||||
|
});
|
||||||
|
|
||||||
|
result.AddRange(sections!);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<DatesRangeDto?> GetDatesRangeAsync(int idWell, int idType, CancellationToken cancellationToken)
|
public async Task<DatesRangeDto?> GetDatesRangeAsync(int idWell, int idType, CancellationToken cancellationToken)
|
||||||
|
Loading…
Reference in New Issue
Block a user